package com.lukouguoji.gjj.holder

import android.view.View
import com.lukouguoji.gjj.databinding.ItemIntImpLoadingListBinding
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.GjjManifest

/**
 * 国际进港装机单 ViewHolder
 */
class IntImpLoadingListViewHolder(view: View) :
    BaseViewHolder<GjjManifest, ItemIntImpLoadingListBinding>(view) {

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

        // 添加图标点击事件 - 切换选择状态
        binding.ivIcon.setOnClickListener {
            bean.checked.set(!bean.checked.get())
            FlowBus.with<String>(ConstantEvent.EVENT_CHECK_CHANGED).tryEmit("check_changed")
            binding.executePendingBindings()
        }

        // 侧滑菜单 - 编辑按钮
        binding.btnEdit.setOnClickListener {
            binding.swipeMenu.quickClose()
            clickListener?.onItemClick(position, 2000)
        }
    }
}
