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.LinearLayout
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 CargoTrackingToLeftListAdapter(val activity: Activity, private val collectList: List<CargoTrackingList>) :
    RecyclerView.Adapter<CargoTrackingToLeftListAdapter.ViewHolder>() {

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

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.cargo_tracking_to_left_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]
        val title = collect.title
        val status = collect.status

        holder.title.text = title
        if (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 == 0) {
            holder.downIcon.visibility = View.VISIBLE
            holder.leftIcon.visibility = View.GONE
        } else {
            holder.downIcon.visibility = View.INVISIBLE
            holder.leftIcon.visibility = View.VISIBLE
        }

        //title为空，说明只占位，不显示
        if (title == "") {
            holder.toLeftItem.visibility = View.INVISIBLE
        } else {
            holder.toLeftItem.visibility = View.VISIBLE
        }

    }

    override fun getItemCount() = collectList.size

}