package com.sixin.module_p.ui.zuzhuang.holder

import android.view.View
import androidx.databinding.ObservableArrayList
import androidx.databinding.ObservableList
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.JianBean
import com.lukouguoji.module_base.ktx.refresh
import com.sixin.module_p.R
import com.sixin.module_p.databinding.ItemPdaZuZhuangBinding

class PdaZuZhuangViewHolder(view: View) :
    BaseViewHolder<GjcBoxAddListBean, ItemPdaZuZhuangBinding>(view) {

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

        binding.rv.adapter = CommonAdapter(
            requireContext(),
            R.layout.item_pda_jian,
            PdaJianViewHolder::class.java
        )
        binding.rv.refresh(bean.jianList)

        binding.ivDown.setOnClickListener {
            val visible = if (binding.rv.visibility == View.VISIBLE) View.GONE else View.VISIBLE
            binding.rv.visibility = visible
            binding.tvJ.visibility = visible
        }

        bean.jianList.addOnListChangedCallback(object :
            ObservableList.OnListChangedCallback<ObservableArrayList<JianBean>>(){
            override fun onChanged(sender: ObservableArrayList<JianBean>?) {
                binding.rv.refresh(bean.jianList)
            }

            override fun onItemRangeChanged(
                sender: ObservableArrayList<JianBean>?,
                positionStart: Int,
                itemCount: Int
            ) {
                binding.rv.refresh(bean.jianList)
            }

            override fun onItemRangeInserted(
                sender: ObservableArrayList<JianBean>?,
                positionStart: Int,
                itemCount: Int
            ) {
                binding.rv.refresh(bean.jianList)
            }

            override fun onItemRangeMoved(
                sender: ObservableArrayList<JianBean>?,
                fromPosition: Int,
                toPosition: Int,
                itemCount: Int
            ) {
                binding.rv.refresh(bean.jianList)
            }

            override fun onItemRangeRemoved(
                sender: ObservableArrayList<JianBean>?,
                positionStart: Int,
                itemCount: Int
            ) {
                binding.rv.refresh(bean.jianList)
            }
        })

        notifyItemClick(position,binding.tvDeleteOrder)
    }
}