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.module_base.common.Constant
import com.lukouguoji.module_base.router.ARouterConstants
import com.lukouguoji.gnc.model.GuoNeiOutCollect
import com.lukouguoji.gnc.page.shouyun.list.GncShouYunListActivity

class GoutCollectionAdapter(val activity: Activity, private val collectList: List<GuoNeiOutCollect>) :
    RecyclerView.Adapter<GoutCollectionAdapter.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 planDate: TextView = view.findViewById(R.id.planDate)
        val planFight: TextView = view.findViewById(R.id.planFight)
        val range: TextView = view.findViewById(R.id.range)
        val spCode: TextView = view.findViewById(R.id.spCode)
        val goods: TextView = view.findViewById(R.id.goods)
    }

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

        viewHolder.itemView.setOnClickListener {

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

            ARouter.getInstance().build(ARouterConstants.ACTIVITY_URL_GOUT_START_COT_ACTIVITY).withInt("wbId", guoNeiOutCollect.mawbId)
                .navigation(activity, Constant.RequestCode.gnc_shouyun_refresh)

        }

        return viewHolder
    }

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

    }

    override fun getItemCount() = collectList.size
}