package com.lukouguoji.gjc.holder

import android.view.View
import com.lukouguoji.gjc.R
import com.lukouguoji.gjc.databinding.ItemIntExpArriveBinding
import com.lukouguoji.module_base.adapter.setCommonAdapter
import com.lukouguoji.module_base.base.BaseViewHolder
import com.lukouguoji.module_base.bean.GjcMaWb
import com.lukouguoji.module_base.ktx.refresh

/**
 * 国际出港-出港运抵 列表项ViewHolder
 */
class IntExpArriveViewHolder(view: View) :
    BaseViewHolder<GjcMaWb, ItemIntExpArriveBinding>(view) {

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

        // 添加图标点击事件 - 切换选择状态
        binding.ivIcon.setOnClickListener {
            // 反转checked状态
            bean.checked.set(!bean.checked.get())

            // 立即更新UI（图片自动切换）
            binding.executePendingBindings()
        }

        // ========== 展开按钮点击事件 ==========
        binding.ivShow.setOnClickListener {
            bean.showMore.set(!bean.showMore.get())
        }

        // ========== 初始化子列表 RecyclerView ==========
        setCommonAdapter(
            binding.rvSub,
            IntExpTallySubViewHolder::class.java,
            R.layout.item_int_exp_tally_sub
        )

        // 刷新子列表数据
        binding.rvSub.refresh(bean.haWbList ?: emptyList())
    }
}
