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.GncQueryList
import com.lukouguoji.module_base.router.ARouterConstants

/**
 * 国内出港查询列表
 */
class GncQueryListAdapter(val activity: Activity, private val collectList: List<GncQueryList>) :
    RecyclerView.Adapter<GncQueryListAdapter.ViewHolder>() {

    inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val no: TextView = view.findViewById(R.id.no)
        val agentCode: TextView = view.findViewById(R.id.agentCode)
        val goods: TextView = view.findViewById(R.id.goods)
        val flight: TextView = view.findViewById(R.id.flight)
        val dest: TextView = view.findViewById(R.id.dest)

        val opDate: TextView = view.findViewById(R.id.opDate)
        val fclose: TextView = view.findViewById(R.id.fclose)
        val pc: TextView = view.findViewById(R.id.pc)
        val weight: TextView = view.findViewById(R.id.weight)
    }

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

        viewHolder.itemView.setOnClickListener {

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

            ARouter.getInstance().build(ARouterConstants.ACTIVITY_URL_GNC_QUERY_INFO).withInt("id", gncQueryList.mawbId)
                .navigation()

        }

        return viewHolder
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val collect = collectList[position]
        holder.no.text = collect.wbNo
        holder.agentCode.text = collect.agentCode
        holder.goods.text = collect.goods
        holder.flight.text = collect.flight
        holder.dest.text = collect.dest

        holder.opDate.text = collect.opDate
        holder.fclose.text = collect.fclose
        holder.pc.text = collect.pc
        holder.weight.text = collect.weight

    }

    override fun getItemCount() = collectList.size

}