package com.lukouguoji.gjj.holder

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

/**
 * 国际进港-事故签证 列表项ViewHolder
 */
class IntImpAccidentVisaViewHolder(view: View) :
    BaseViewHolder<IntImpAccidentVisaBean, ItemIntImpAccidentVisaBinding>(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.ll.setOnClickListener {
            clickListener?.onItemClick(position, 1000)  // type=1000表示查看详情
        }

        // 侧滑菜单 - 修改按钮
        binding.btnEdit.setOnClickListener {
            binding.swipeMenu.quickClose()
            clickListener?.onItemClick(position, 2000)  // type=2000表示修改操作
        }

        // 侧滑菜单 - 删除按钮
        binding.btnDelete.setOnClickListener {
            binding.swipeMenu.quickClose()
            clickListener?.onItemClick(position, 3000)  // type=3000表示删除操作
        }
    }
}
