package com.lukouguoji.gjc.holder

import android.view.View
import com.lukouguoji.gjc.databinding.ItemIntExpLoadBinding
import com.lukouguoji.module_base.base.BaseViewHolder
import com.lukouguoji.module_base.common.ConstantEvent
import com.lukouguoji.module_base.impl.FlowBus
import com.lukouguoji.module_base.bean.GjcExportLoad

/**
 * 国际出港-出港装载 列表项ViewHolder
 */
class IntExpLoadViewHolder(view: View) :
    BaseViewHolder<GjcExportLoad, ItemIntExpLoadBinding>(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())
            FlowBus.with<String>(ConstantEvent.EVENT_CHECK_CHANGED).tryEmit("check_changed")

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