package com.zxbw.modulemain.adapter

import android.app.Activity
import android.graphics.Color
import android.text.TextUtils
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.zxbw.modulemain.R
import com.zxhl.cms.AppContext
import com.zxhl.cms.common.base.BaseRecyclerAdapter
import com.zxhl.cms.net.model.qy.SkillEntity
import com.zxhl.cms.utils.OnRecycleItemClickListener

class TimeAdapter : BaseRecyclerAdapter<SkillEntity, TimeAdapter.ViewHolder> {
    private var mContext: Activity? = null
    private var pos = -1
    private val listener: OnRecycleItemClickListener<SkillEntity>
    private val mSelectColor: Int
    private val mUnSelectColor: Int
    constructor(
        content: Activity?,
        listener: OnRecycleItemClickListener<SkillEntity>
    ) : super() {
        mContext = content
        this.listener = listener
        mSelectColor = AppContext.get().resources.getColor(R.color.white)
        mUnSelectColor = AppContext.get().resources.getColor(R.color.color_e09a9a)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
       var bean = mList[position]
        Log.e("MXL","Pos:"+pos)
        if(position==pos){
            holder.id_tv_time?.setTextColor(mSelectColor)
            holder.id_tv_status_desc?.setTextColor(mSelectColor)
        }else{
            holder.id_tv_time?.setTextColor(mUnSelectColor)
            holder.id_tv_status_desc?.setTextColor(mUnSelectColor)
        }
//        holder.id_ll_item?.setOnClickListener {
//
//        }
        holder.id_tv_time?.text="${bean.startTime}"
        holder.id_tv_status_desc?.text="${bean.statusDesc}"
    }
//    override fun getItemCount(): Int {
//        val size = mList.size
//        if (size > 4) {
//            return 4
//        } else {
//            return size
//        }
//    }
    fun setPosition(pos: Int) {
        this.pos = pos
        notifyDataSetChanged()
    }
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        return ViewHolder(
            LayoutInflater.from(AppContext.get())
                .inflate(R.layout.item_layout_skill_time, parent, false)
        )
    }

    inner  class ViewHolder : RecyclerView.ViewHolder {
        var id_ll_item: LinearLayout?
        var id_tv_status_desc: TextView?
        var id_tv_time: TextView?


        constructor(
            itemView: View
        ) : super(itemView) {
            id_ll_item =
                itemView.findViewById<LinearLayout>(R.id.id_ll_item)
            id_tv_time = itemView.findViewById<TextView>(R.id.id_tv_time)
            id_tv_status_desc = itemView.findViewById<TextView>(R.id.id_tv_status_desc)
            id_ll_item?.setOnClickListener {
                val pos = adapterPosition
                if (pos >= 0 && pos < mList.size) {
                    setPosition(pos)
                    notifyDataSetChanged()
                    listener.onItemClick(it, position, mList[pos])
                }
            }
        }
    }
}