package com.remax.visualnovel.widget.itemdecoration

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

class SpaceItemDecoration constructor(
    private var top: Int = 0,
    private var left: Int = 0,
    private var bottom: Int = 0,
    private var right: Int = 0,
    private var headerCount: Int = 0
) : RecyclerView.ItemDecoration() {

    constructor(horizontal: Int, vertical: Int, headerCount: Int = 0) : this() {
        top = vertical
        bottom = vertical

        left = horizontal
        right = horizontal

        this.headerCount = headerCount
    }

    override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
        super.getItemOffsets(outRect, view, parent, state)
        val position = parent.getChildAdapterPosition(view)
        if (position < headerCount) {
            return
        }
        if (top > 0) outRect.top = top
        if (left > 0) outRect.left = left
        if (bottom > 0) outRect.bottom = bottom
        if (right > 0) outRect.right = right
    }
}