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.alibaba.android.arouter.launcher.ARouter
import com.lukouguoji.gnc.R
import com.lukouguoji.gnc.model.GncTransferList
import com.lukouguoji.module_base.router.ARouterConstants

/**
 * 国内出港转运列表
 */
class GncTransferListAdapter(val activity: Activity, private val collectList: List<GncTransferList>) :
    RecyclerView.Adapter<GncTransferListAdapter.ViewHolder>() {

    inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val carId: TextView = view.findViewById(R.id.carId)
        val transId: TextView = view.findViewById(R.id.transId)
        val transDate: TextView = view.findViewById(R.id.transDate)
    }

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

        viewHolder.itemView.setOnClickListener {
            val adapterPosition = viewHolder.adapterPosition
            if (adapterPosition < 0 || collectList.isEmpty()) {
                return@setOnClickListener
            }
            val gncTransferList = collectList[adapterPosition]
            ARouter.getInstance().build(ARouterConstants.ACTIVITY_URL_GOUT_TRANSFER_INFO_ACTIVITY).withInt("id", gncTransferList.mawbId)
                .navigation()

        }

        return viewHolder
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val collect = collectList[position]
        holder.carId.text = collect.carId
        holder.transId.text = collect.transId
        holder.transDate.text = collect.transDate
    }

    override fun getItemCount() = collectList.size

}