package com.audio.record.screen.test.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.audio.record.screen.test.base.BaseAdapter
import com.audio.record.screen.test.data.ImageGroup
import com.audio.record.screen.test.data.VideoGroup
import com.audio.record.screen.test.databinding.AdapterVideoDateBinding
import com.audio.record.screen.test.tool.Extend.dpToPx
import com.audio.record.screen.test.tool.NoScrollLinearLayoutManager
import com.audio.record.screen.test.view.GridSpacingItemDecoration

class ImageGroupAdapter(context: Context, private var click: (cropRatio: String) -> Unit) :
    BaseAdapter<ImageGroup, AdapterVideoDateBinding>(context) {
    override fun getViewBinding(parent: ViewGroup?): AdapterVideoDateBinding {
        return AdapterVideoDateBinding.inflate(LayoutInflater.from(parent!!.context), parent, false)
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        val itemHolder: VHolder<AdapterVideoDateBinding> =
            holder as VHolder<AdapterVideoDateBinding>

        val item = data[position]
        itemHolder.vb.run {

            tvDate.text = item.date

            videoInfoRecycler.run {
                adapter = ImageInfoAdapter(mContext, position == 0) {}.apply {
                    updateData(item.images)
                }
                if (this.layoutManager == null) {
                    layoutManager = GridLayoutManager(mContext, 3)
                }
                isNestedScrollingEnabled = false
                setHasFixedSize(false)
                if (this.itemDecorationCount <= 0) {
                    val gridSpacingItemDecoration =
                        GridSpacingItemDecoration(3, 5.dpToPx(mContext), true)
                    addItemDecoration(gridSpacingItemDecoration)
                }


            }
        }
    }

}