package com.lukouguoji.gjj.holder

import android.view.View
import com.lukouguoji.gjj.R
import com.lukouguoji.gjj.databinding.ItemTallyAddBinding
import com.lukouguoji.module_base.base.BaseViewHolder
import com.lukouguoji.module_base.base.CommonAdapter
import com.lukouguoji.module_base.bean.GjcBoxAddListBean
import com.lukouguoji.module_base.bean.GjjTallyAddBean
import com.lukouguoji.module_base.impl.ListChangedCallBackImpl
import com.lukouguoji.module_base.interfaces.IOnItemClickListener
import com.lukouguoji.module_base.ktx.addOnItemClickListener
import com.lukouguoji.module_base.ktx.refresh

class TallyAddListViewHolder(view: View) :
    BaseViewHolder<GjjTallyAddBean, ItemTallyAddBinding>(view) {

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

        binding.bean = bean

        binding.rv.adapter = CommonAdapter(
            itemView.context,
            R.layout.item_jian,
            JianViewHolder::class.java
        )

        binding.rv.addOnItemClickListener(object : IOnItemClickListener {
            override fun onItemClick(position: Int, type: Int) {
                val jianBean = bean.jianList[position]
                jianBean.checked.set(!jianBean.checked.get())
            }
        })

        binding.rv.refresh(bean.jianList)
        bean.jianList.addOnListChangedCallback(ListChangedCallBackImpl() {
            binding.rv.refresh(bean.jianList)
        })

        notifyItemClick(position, binding.tvBatch)
        notifyItemClick(position, binding.tvDeleteOrder)
        notifyItemClick(position, binding.tvDeleteMatter)
        notifyItemClick(position, binding.ivShow)
    }
}