package com.lukouguoji.gnc.adapt

import android.app.Activity
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.android.arouter.launcher.ARouter
import com.github.gzuliyujiang.dialog.DialogLog.print
import com.lukouguoji.gnc.R
import com.lukouguoji.gnc.model.GncFuBangList
import com.lukouguoji.module_base.common.Constant
import com.lukouguoji.module_base.router.ARouterConstants

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

    inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val no: TextView = view.findViewById(R.id.no)
        val dest: TextView = view.findViewById(R.id.dest)
        val guobangWeight: TextView = view.findViewById(R.id.guobangWeight)
        val weight: TextView = view.findViewById(R.id.weight)
        val pc: TextView = view.findViewById(R.id.pc)
        val guobangDate: TextView = view.findViewById(R.id.guobangDate)
    }

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

        viewHolder.itemView.setOnClickListener {
            val adapterPosition = viewHolder.adapterPosition
            Log.i("刷新：${viewHolder.adapterPosition} ","刷新")
            if (adapterPosition < 0 || collectList.isEmpty()) {
                return@setOnClickListener
            }
            val gncFuBang = collectList[adapterPosition]

            ARouter.getInstance().build(ARouterConstants.ACTIVITY_URL_GOUT_FU_BANG_ACTIVITY).withString("userIdParam", gncFuBang.useId.toString())
                .navigation(activity, Constant.RequestCode.gnc_shouyun_list_refresh)

        }

        return viewHolder
    }

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

    override fun getItemCount() = collectList.size

}