package com.lukouguoji.gjj.holder

import android.view.View
import com.lukouguoji.gjj.activity.IntImpPickUpRecordDetailsActivity
import com.lukouguoji.gjj.databinding.ItemIntImpPickUpRecordBinding
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.IntImpPickUpRecordBean

/**
 * 国际进港-提取记录 ViewHolder
 */
class IntImpPickUpRecordViewHolder(view: View) :
    BaseViewHolder<IntImpPickUpRecordBean, ItemIntImpPickUpRecordBinding>(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 {
            IntImpPickUpRecordDetailsActivity.start(itemView.context, bean)
        }

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