package com.zxbw.modulemain.adapter

import android.app.Activity
import android.graphics.Color
import android.graphics.Paint
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.RightsDetailEntity
import com.zxhl.cms.utils.OnRecycleItemClickListener


class XymhRightsDetailListAdapter :
    BaseRecyclerAdapter<RightsDetailEntity, XymhRightsDetailListAdapter.ViewHolder> {
    private var mContext: Activity? = null
    private val listener: OnRecycleItemClickListener<RightsDetailEntity>
    private var mSelectPos: Int = -1;

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


    fun setSelectPos(pos: Int) {
        mSelectPos = pos
        notifyDataSetChanged()
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val bean = mList[position]
        holder.id_tv_rights_name?.text = bean.brand
        holder.id_tv_rights_desc?.text = "${bean.category}${bean.goodsName}"
        holder.id_tv_rights_price?.text = "${bean.salePrice}"
        holder.id_tv_rights_old_price?.text = "¥${bean.originPrice}"
        holder.id_tv_rights_old_price?.paint?.flags = Paint.STRIKE_THRU_TEXT_FLAG //中划线

        if (position == mSelectPos) {
            holder.id_ll_rights_item_view?.setBackgroundResource(R.drawable.img_rights_item_click)
            holder.id_tv_rights_name?.setTextColor(Color.parseColor("#BA7E36"))
            holder.id_tv_rights_desc?.setTextColor(Color.parseColor("#BA7E36"))
            holder.id_tv_rights_price?.setTextColor(Color.parseColor("#BA7E36"))
            holder.id_tv_rights_old_price?.setTextColor(Color.parseColor("#BA7E36"))
            holder.id_tv_rights_old_price_desc?.setTextColor(Color.parseColor("#BA7E36"))

        } else {
            holder.id_ll_rights_item_view?.setBackgroundResource(R.drawable.img_rights_item_default)
            holder.id_tv_rights_name?.setTextColor(Color.parseColor("#999999"))
            holder.id_tv_rights_desc?.setTextColor(Color.parseColor("#999999"))
            holder.id_tv_rights_price?.setTextColor(Color.parseColor("#999999"))
            holder.id_tv_rights_old_price?.setTextColor(Color.parseColor("#999999"))
            holder.id_tv_rights_old_price_desc?.setTextColor(Color.parseColor("#999999"))
        }

        holder.id_ll_rights_item_view?.setOnClickListener {
            listener.onItemClick(it, position, bean)
        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        return ViewHolder(
            LayoutInflater.from(AppContext.get())
                .inflate(R.layout.item_layout_rights_detail_view, parent, false)
        )
    }

    class ViewHolder : RecyclerView.ViewHolder {
        var id_ll_rights_item_view: LinearLayout?
        var id_tv_rights_name: TextView?
        var id_tv_rights_desc: TextView?
        var id_tv_rights_price: TextView?
        var id_tv_rights_old_price: TextView?
        var id_tv_rights_old_price_desc: TextView?

        constructor(
            itemView: View
        ) : super(itemView) {
            id_ll_rights_item_view =
                itemView.findViewById<LinearLayout>(R.id.id_ll_rights_item_view)
            id_tv_rights_name = itemView.findViewById<TextView>(R.id.id_tv_rights_name)
            id_tv_rights_desc = itemView.findViewById<TextView>(R.id.id_tv_rights_desc)
            id_tv_rights_price = itemView.findViewById<TextView>(R.id.id_tv_rights_price)
            id_tv_rights_old_price = itemView.findViewById<TextView>(R.id.id_tv_rights_old_price)
            id_tv_rights_old_price_desc = itemView.findViewById<TextView>(R.id.id_tv_rights_old_price_desc)

        }
    }
}