package com.lukouguoji.gnj.adapt

import android.app.Activity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

import com.lukouguoji.gnj.R
import com.lukouguoji.gnj.model.GnjRuKuRef

/**
 * 复磅列表
 */
class GnjRuKuRefListAdapter(val activity: Activity, private val collectList: List<GnjRuKuRef>) :
    RecyclerView.Adapter<GnjRuKuRefListAdapter.ViewHolder>() {

    inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val leftIcon: ImageView = view.findViewById(R.id.leftIcon)

        val no: TextView = view.findViewById(R.id.no)
        val confirmId: TextView = view.findViewById(R.id.confirmId)
        val confirmDate: TextView = view.findViewById(R.id.confirmDate)
        /*val totalPc: TextView = view.findViewById(R.id.totalPc)
        val pc: TextView = view.findViewById(R.id.pc)
        val weight: TextView = view.findViewById(R.id.weight)
        val cashWeight: TextView = view.findViewById(R.id.cashWeight)
        val origin: TextView = view.findViewById(R.id.origin)
        val dest: TextView = view.findViewById(R.id.dest)
        val agentCode: TextView = view.findViewById(R.id.agentCode)
        val spCode: TextView = view.findViewById(R.id.spCode)
        val goods: TextView = view.findViewById(R.id.goods)*/
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.gnj_ru_ku_ref_list_item, parent, false)
        val viewHolder = ViewHolder(view)

        /*viewHolder.itemView.setOnClickListener {

            var adapterPosition = viewHolder.adapterPosition
            var guoNeiOutCollect = collectList[adapterPosition]

            ARouter.getInstance().build(ARouterConstants.ACTIVITY_URL_GOUT_START_COT_ACTIVITY).withInt("wbId", guoNeiOutCollect.mawbId)
                .navigation(activity, Constant.RequestCode.gnc_shouyun_refresh)

        }*/

        return viewHolder
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val collect = collectList[position]

        holder.no.text = collect.wbNo
        holder.confirmId.text = collect.confirmId
        holder.confirmDate.text = collect.confirmDate
        //有确认时间的，不可被选中
   /*     if (collect.confirmDate != "") {
            collect.isCheck = false
        }*/

        val leftIcon = holder.leftIcon
        //选中
        if (collect.isCheck) {
            leftIcon.setImageResource(R.mipmap.gnj_cang_dan_left_icon_check)
        } else {
            leftIcon.setImageResource(R.mipmap.list_item_left_icon)
        }
        //击触发选中事件
        leftIcon.setOnClickListener {
            collect.isCheck = !collect.isCheck
            notifyDataSetChanged() // 更新数据
        }


        /*holder.totalPc.text = collect.totalPc.toString()
        holder.pc.text = collect.pc.toString()
        holder.weight.text = "${collect.weight} KG"
        holder.cashWeight.text = "${collect.cashWeight} KG"

        holder.origin.text = collect.origin
        holder.dest.text = collect.dest
        holder.agentCode.text = collect.agentCode
        holder.spCode.text = collect.spCode
        holder.goods.text = collect.goods*/

    }

    override fun getItemCount() = collectList.size

}