package com.lukouguoji.gjc.holder

import android.view.View
import com.lukouguoji.gjc.R
import com.lukouguoji.gjc.activity.GjcBoxWeighingDetailsActivity
import com.lukouguoji.gjc.databinding.ItemGjcBoxWeighingBinding
import com.lukouguoji.module_base.base.BaseViewHolder
import com.lukouguoji.module_base.bean.GjcUldUseBean

/**
 * 国际出港板箱过磅列表 ViewHolder
 */
class GjcBoxWeighingViewHolder(view: View) :
    BaseViewHolder<GjcUldUseBean, ItemGjcBoxWeighingBinding>(view) {

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

        // 更新图标状态
        updateIcon(bean)

        // 图标点击切换选中状态
        binding.ivIcon.setOnClickListener {
            bean.checked.set(!bean.checked.get())
            updateIcon(bean)
        }

        // 整行点击跳转到详情页
        binding.ll.setOnClickListener {
            GjcBoxWeighingDetailsActivity.start(it.context, bean.useId)
        }
    }

    private fun updateIcon(bean: GjcUldUseBean) {
        binding.ivIcon.setImageResource(
            if (bean.checked.get()) R.drawable.img_plane_s else R.drawable.img_plane
        )
    }
}
