package com.zxhl.cms.pay.adapter

import android.content.Context
import android.graphics.Color
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.zxhl.cms.R
import com.zxhl.cms.common.base.BaseRecyclerAdapter
import com.zxhl.cms.net.model.pay.VipPayEntity
import com.zxhl.cms.utils.OnRecycleItemClickListener

/**
 * @author (wangXuewei)
 * @datetime 2022-04-12 19:04 GMT+8
 * @detail :
 */
class BecomeVipPriceAdapter : BaseRecyclerAdapter<VipPayEntity, BecomeVipPriceAdapter.ViewHolder> {
    private var mContext: Context? = null
    private var mPosition = 0
    private val listener: OnRecycleItemClickListener<VipPayEntity>

    constructor(
        content: Context?,
        listener: OnRecycleItemClickListener<VipPayEntity>
    ) : super() {
        this.listener = listener
        mContext = content
    }

    fun setSelectView(position: Int) {
        mPosition = position;
        notifyDataSetChanged()
    }

    override fun onCreateViewHolder(holder: ViewGroup, p1: Int): BecomeVipPriceAdapter.ViewHolder {
        return ViewHolder(
            LayoutInflater.from(holder.context)
                .inflate(R.layout.item_layout_become_vip_price_view, holder, false)
        )
    }

    override fun onBindViewHolder(holder: BecomeVipPriceAdapter.ViewHolder, position: Int) {
//        val data = mList[position]
        holder.id_vip_time.text = "1 Week"
        holder.id_vip_money.text = "$${2.99}"
        if (mPosition==position){
            holder.id_item_view.background = mContext?.getDrawable(R.drawable.shape_8857ff_bd8aff_bg_r10)
            holder.id_vip_time.setTextColor(Color.parseColor("#FFFFFF"))
            holder.id_vip_money.setTextColor(Color.parseColor("#FFFFFF"))
        }else{
            holder.id_item_view.background = mContext?.getDrawable(R.drawable.shape_white_r10)
            holder.id_vip_time.setTextColor(Color.parseColor("#333333"))
            holder.id_vip_money.setTextColor(Color.parseColor("#333333"))
        }
        holder.id_item_view?.setOnClickListener {
            listener.onItemClick(it,position,null)
        }
    }

    override fun getItemCount(): Int {
        return 3
    }

    inner class ViewHolder : RecyclerView.ViewHolder {


        var id_vip_time: TextView
        var id_vip_money: TextView
        var id_item_view: LinearLayout

        constructor(itemView: View) : super(itemView) {
            id_item_view = itemView.findViewById(R.id.id_ll_become_vip_view)
            id_vip_time = itemView.findViewById(R.id.id_tv_item_vip_time)
            id_vip_money = itemView.findViewById(R.id.id_tv_item_vip_price)
        }
    }

}