package com.lukouguoji.gjc.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.alibaba.android.arouter.launcher.ARouter
import com.lukouguoji.gjc.R
import com.lukouguoji.gjc.model.GjcReceive
import com.lukouguoji.module_base.common.Constant
import com.lukouguoji.module_base.router.ARouterConstants

class GjcReceiveListAdapter(val activity: Activity, private val collectList: List<GjcReceive>) :
    RecyclerView.Adapter<GjcReceiveListAdapter.ViewHolder>() {

    inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val no: TextView = view.findViewById(R.id.no)
        val pc: TextView = view.findViewById(R.id.pc)
        val weight: TextView = view.findViewById(R.id.weight)
        val agentCode: TextView = view.findViewById(R.id.agentCode)
        val spCode: TextView = view.findViewById(R.id.spCode)
        val goods: TextView = view.findViewById(R.id.goods)
        val flight: TextView = view.findViewById(R.id.flight)
        val businessType: TextView = view.findViewById(R.id.businessType)
    }

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

        viewHolder.itemView.setOnClickListener {

            var adapterPosition = viewHolder.adapterPosition
            if (adapterPosition < 0 || collectList.isEmpty()) {
                return@setOnClickListener
            }
            var collect = collectList[adapterPosition]

            ARouter.getInstance().build(ARouterConstants.ACTIVITY_URL_GJC_START_RECEIVE).withInt("wbId", collect.mawbId)
                .navigation(activity, Constant.RequestCode.gjc_shouyun_refresh)

        }

        return viewHolder
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val collect = collectList[position]
        holder.no.text = collect.wbNo
        holder.pc.text = collect.pc.toString()
        holder.weight.text = "${collect.weight} KG"
        holder.agentCode.text = collect.agentCode
        holder.spCode.text = collect.spCode
        holder.goods.text = collect.goods
        holder.flight.text = collect.flight
        holder.businessType.text = collect.businessType

    }

    override fun getItemCount() = collectList.size
}