package com.lukouguoji.gnc.adapt

import android.app.Activity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.lukouguoji.gnc.R
import com.lukouguoji.gnc.model.GncQueryInfoWh

class GncQueryInfoWhListAdapter(val activity: Activity, val collectList: MutableList<GncQueryInfoWh>) :
    RecyclerView.Adapter<GncQueryInfoWhListAdapter.ViewHolder>() {

    inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val location: TextView = view.findViewById(R.id.location)
        val pc: TextView = view.findViewById(R.id.pc)
        val weight: TextView = view.findViewById(R.id.weight)
        val flight: TextView = view.findViewById(R.id.flight)
        val opDate: TextView = view.findViewById(R.id.opDate)
        val fclose: TextView = view.findViewById(R.id.fclose)
        val opId: TextView = view.findViewById(R.id.opId)
    }

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

        /* viewHolder.itemView.setOnClickListener {

             var adapterPosition = viewHolder.adapterPosition
             var 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.location.text = collect.location
        holder.pc.text = collect.pc.toString()
        holder.weight.text = "${collect.weight} KG"
        holder.flight.text = collect.flight
        holder.opDate.text = collect.opDate
        holder.fclose.text = collect.fclose
        holder.opId.text = collect.opId
    }

    override fun getItemCount() = collectList.size

    fun append(gncQueryInfoWh: GncQueryInfoWh) {
        collectList.add(gncQueryInfoWh)
        notifyDataSetChanged()
    }
}