package com.lukouguoji.gjc.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.gjc.R
import com.lukouguoji.gjc.model.GjcYiKu2ListModel


class GjcYiKu2ListAdapter(
    val activity: Activity,
    private val collectList: MutableList<GjcYiKu2ListModel>
) :
    RecyclerView.Adapter<GjcYiKu2ListAdapter.ViewHolder>() {

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

        val pc: TextView = view.findViewById(R.id.pc)
        val weight: TextView = view.findViewById(R.id.weight)
        val goods: TextView = view.findViewById(R.id.goods)
        val agentCode: TextView = view.findViewById(R.id.agentCode)
        val spCode: TextView = view.findViewById(R.id.spCode)

        val origin: TextView = view.findViewById(R.id.origin)//始发港
        val dest: TextView = view.findViewById(R.id.dest)//目的港
        val by1: TextView = view.findViewById(R.id.by1)//承运人
        val awbType: TextView = view.findViewById(R.id.awbType)//运单类型
    }

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

        return viewHolder
    }

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

        val leftIcon = holder.leftIcon
        //选中
        if (collect.isCheck) {
            leftIcon.setImageResource(R.mipmap.gjc_yi_ku_left_icon_check)
        } else {
            leftIcon.setImageResource(R.mipmap.gnc_ware_house_left_icon)
        }

        holder.wbNo.text = collect.wbNo
        holder.id.text = collect.id
        holder.pc.text = "${collect.pc}"
        holder.weight.text = "${collect.weight} KG"
        holder.goods.text = collect.goods
        holder.spCode.text = collect.spCode
        holder.agentCode.text = collect.agentCode

        holder.origin.text = collect.origin
        holder.dest.text = collect.dest
        holder.by1.text = collect.by1
        holder.awbType.text = collect.awbType

    }

    override fun getItemCount() = collectList.size

    fun append(gjcYiKu2ListModel: GjcYiKu2ListModel) {
        collectList.add(gjcYiKu2ListModel)
        notifyDataSetChanged()
    }

}