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.alibaba.android.arouter.launcher.ARouter
import com.lukouguoji.gnj.R
import com.lukouguoji.gnj.model.GnjCangDanListModel
import com.lukouguoji.gnj.model.GnjChuKuListModel
import com.lukouguoji.gnj.viewModel.GnjChuKuListViewModel
import com.lukouguoji.module_base.common.Constant
import com.lukouguoji.module_base.router.ARouterConstants

class GnjChuKuListAdapter(
    val activity: Activity,
    private val viewModel: GnjChuKuListViewModel,
    private val collectList: MutableList<GnjChuKuListModel>
) :
    RecyclerView.Adapter<GnjChuKuListAdapter.ViewHolder>() {

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

        val fdate: TextView = view.findViewById(R.id.fdate)
        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 pickDate: TextView = view.findViewById(R.id.pickDate)

    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.gnj_chu_ku_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.gnj_cang_dan_left_icon_check)
        } else {
            leftIcon.setImageResource(R.mipmap.gnc_ware_house_left_icon)
        }

        holder.wbNo.text = collect.wbNo
        holder.pickNo.text = collect.pickNo.toString()
        holder.fno.text = collect.fno
        holder.pc.text = "${collect.pc}"
        holder.weight.text = "${collect.weight} KG"

        holder.fdate.text = collect.fdate
        holder.goods.text = collect.goods
        holder.agentCode.text = collect.agentCode
        holder.spCode.text = collect.spCode
        holder.pickDate.text = collect.pickDate

        leftIcon.setOnClickListener {
            collect.isCheck = !collect.isCheck
            if (collect.isCheck) {
//                viewModel.plusOne()
            } else {
//                viewModel.subOne()
            }
            notifyDataSetChanged() // 更新数据
        }

    }

    override fun getItemCount() = collectList.size

    fun append(gnjChuKuListModel: GnjChuKuListModel) {
        collectList.add(gnjChuKuListModel)
        notifyDataSetChanged()
    }

}