package com.adealink.weparty.profile.ui.photowall.itemdecoration

import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView

class SpacingItemDecoration(
    var spanCount: Int,
    var spacingH: Int,
    private val spacingV: Int,
) : RecyclerView.ItemDecoration() {

    override fun getItemOffsets(
        outRect: Rect,
        view: View,
        parent: RecyclerView,
        state: RecyclerView.State
    ) {
        super.getItemOffsets(outRect, view, parent, state)

        val position = parent.getChildAdapterPosition(view)

        val column = position % spanCount

        outRect.left = spacingH - column * spacingH / spanCount
        outRect.right = (column + 1) * spacingH / spanCount

        if (position < spanCount) {
            outRect.top = spacingV
        }
        outRect.bottom = spacingV
    }
}