package com.lukouguoji.gnc.adapt

import android.annotation.SuppressLint
import android.app.Activity
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.android.arouter.launcher.ARouter
import com.alibaba.fastjson.JSONObject
import com.github.gzuliyujiang.dialog.DialogLog.print
import com.lukouguoji.gnc.R
import com.lukouguoji.gnc.activity.GoutChuKuListActivity
import com.lukouguoji.gnc.model.GncFuBangList
import com.lukouguoji.module_base.common.Constant
import com.lukouguoji.module_base.http.user.UserNetwork
import com.lukouguoji.module_base.router.ARouterConstants
import com.lukouguoji.module_base.util.Common

/**
 * 出库，装机列表
 */
class GncChuKuListAdapter(val activity: Activity, private val collectList: List<GncFuBangList>) :
    RecyclerView.Adapter<GncChuKuListAdapter.ViewHolder>() {

    inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val no: TextView = view.findViewById(R.id.no)
        val fno: TextView = view.findViewById(R.id.fno)
        val dest: TextView = view.findViewById(R.id.dest)
        val guobangWeight: TextView = view.findViewById(R.id.guobangWeight)
        val outer: TextView = view.findViewById(R.id.outer)
        val loader: TextView = view.findViewById(R.id.loader)
        val pc: TextView = view.findViewById(R.id.pc)
       var chuku: Button =view.findViewById(R.id.button_chuke)
       // var load: Button =view.findViewById(R.id.button_load)
    }

    @SuppressLint("SuspiciousIndentation")
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.gnc_chu_ku_list_item, parent, false)
        val viewHolder = ViewHolder(view)
        viewHolder.chuku.setOnClickListener({
            val adapterPosition = viewHolder.adapterPosition
            val gncFuBang = collectList[adapterPosition]
            if(adapterPosition>=0){
             var a: GoutChuKuListActivity= activity as GoutChuKuListActivity
                a.ChuKu(gncFuBang.useId,gncFuBang.carId)
            }
        })
      /*  viewHolder.load.setOnClickListener({
            val adapterPosition = viewHolder.adapterPosition
            val gncFuBang = collectList[adapterPosition]
            if(adapterPosition>=0){
                var a: GoutChuKuListActivity= activity as GoutChuKuListActivity
                a.viewModel.load(gncFuBang.useId,gncFuBang.carId)
                return@setOnClickListener
            }
        })*/
        viewHolder.itemView.setOnClickListener {
            val adapterPosition = viewHolder.adapterPosition
         //   Log.i("刷新：${viewHolder.adapterPosition} ","刷新")
            if (adapterPosition < 0 || collectList.isEmpty()) {
                return@setOnClickListener
            }
            val gncFuBang = collectList[adapterPosition]



        }

        return viewHolder
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val collect = collectList[position]
        holder.no.text = collect.carId
        holder.fno.text = collect.fno
        holder.dest.text = collect.fdest
        holder.guobangWeight.text = "${collect.weight} KG"
        holder.outer.text = collect.outer
        holder.loader.text=collect.loader
        holder.pc.text = collect.pc.toString()
    }

    override fun getItemCount() = collectList.size

}