package com.lukouguoji.cargo.adapt

import android.app.Activity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.lukouguoji.cargo.R
import com.lukouguoji.cargo.model.CargoTrackingList

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

    inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val title: TextView = view.findViewById(R.id.title)
        val rightIcon: ImageView = view.findViewById(R.id.rightIcon)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.cargo_tracking_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_GJJ_QUERY_INFO).withInt("id", gncQueryList.mawbId)
                .navigation()

        }*/

        return viewHolder
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val collect = collectList[position]
        holder.title.text = collect.title
        if (collect.status) {
            holder.title.background = ContextCompat.getDrawable(activity, R.drawable.sel_round_shape);
        } else {
            holder.title.background = ContextCompat.getDrawable(activity, R.drawable.round_shape);
        }

        if (position == collectList.size - 1) {
            holder.rightIcon.visibility = View.GONE
        }else{
            holder.rightIcon.visibility = View.VISIBLE
        }

    }

    override fun getItemCount() = collectList.size

}