package com.lukouguoji.gjc.holder

import android.view.View
import com.lukouguoji.gjc.activity.GjcWeighingRecordDetailsActivity
import com.lukouguoji.gjc.activity.GjcWeighingWbDetailActivity
import com.lukouguoji.gjc.databinding.ItemGjcWeighingRecordBinding
import com.lukouguoji.module_base.base.BaseViewHolder
import com.lukouguoji.module_base.bean.GjcWeighingRecordBean

/**
 * 国际出港计重记录列表 ViewHolder
 *
 * item 布局分平板（layout-sw600dp/item_gjc_weighing_record.xml，含选择图标 iv_icon）
 * 与手机（layout/item_gjc_weighing_record.xml，卡片式，地磅图标 iv_scale 进计重明细、
 * 「查看详情」tv_detail 进运单详情）两个变体，单侧独有的 id 需判空调用。
 */
class GjcWeighingRecordViewHolder(view: View) :
    BaseViewHolder<GjcWeighingRecordBean, ItemGjcWeighingRecordBinding>(view) {

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

        // 图标点击 - 切换选择状态（平板独有）
        binding.ivIcon?.setOnClickListener {
            // 反转checked状态
            bean.checked.set(!bean.checked.get())

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

        // 地磅图标点击进计重明细（手机独有）
        binding.ivScale?.setOnClickListener {
            GjcWeighingRecordDetailsActivity.start(it.context, bean)
        }

        // 「查看详情」进运单详情（手机独有页面）
        binding.tvDetail?.setOnClickListener {
            GjcWeighingWbDetailActivity.start(it.context, bean)
        }

        // 整行点击跳转到计重明细页
        binding.ll.setOnClickListener {
            GjcWeighingRecordDetailsActivity.start(it.context, bean)
        }
    }
}
