package com.lukouguoji.gjc.holder

import android.view.View
import androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
import com.lukouguoji.gjc.R
import com.lukouguoji.gjc.databinding.ItemGoodsAddBinding
import com.lukouguoji.module_base.base.BaseViewHolder
import com.lukouguoji.module_base.base.CommonAdapter
import com.lukouguoji.module_base.bean.GjcGoodsAddBean
import com.lukouguoji.module_base.ktx.slipList

class GjcGoodsAddViewHolder(view: View) :
    BaseViewHolder<GjcGoodsAddBean, ItemGoodsAddBinding>(view) {

    override fun onBind(item: Any?, position: Int) {
        val bean = getItemBean(item) ?: return
        binding.bean = bean

        val adapter = CommonAdapter(
            requireContext(),
            R.layout.item_goods_add_show,
            GjcGoodsAddShowViewHolder::class.java
        )
        binding.vp.adapter = adapter
        adapter.refresh(bean.warehouseList?.slipList(5))

        binding.vp.registerOnPageChangeCallback(object : OnPageChangeCallback() {
            override fun onPageSelected(position: Int) {
                binding.tvIndex.text = "${position + 1}/${adapter.itemCount}"
            }
        })

        notifyItemClick(position, binding.ivShow)
        notifyItemClick(position, binding.tvDelete)
    }

}