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

/**
 * 国际出港查询列表
 */
class GjcQueryListAdapter(val activity: Activity, private val collectList: List<GjcQueryList>) :
    RecyclerView.Adapter<GjcQueryListAdapter.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 range: TextView = view.findViewById(R.id.range)

        val fclose: TextView = view.findViewById(R.id.fclose)
        val businessType: TextView = view.findViewById(R.id.businessType)
        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.gjc_query_list_item, parent, false)
        val viewHolder = ViewHolder(view)

        viewHolder.itemView.setOnClickListener {

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

            ARouter.getInstance().build(ARouterConstants.ACTIVITY_URL_GJC_QUERY_INFO).withInt("id", GjcQueryList.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.range.text = collect.range

        holder.fclose.text = collect.fclose
        holder.businessType.text = collect.businessType
        holder.pc.text = collect.pc
        holder.weight.text = collect.weight
    }

    override fun getItemCount() = collectList.size

}