package com.zxbw.modulemain.adapter

import android.app.Activity
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.JgqQyEntity
import com.zxhl.cms.net.model.qy.RightsDetailEntity
import com.zxhl.cms.utils.OnRecycleItemClickListener
import com.zxhl.cms.widget.RecycleImageView

class CardAdapter : BaseRecyclerAdapter<RightsDetailEntity, CardAdapter.ViewHolder> {
    private var mContext: Activity? = null
    private val listener: OnRecycleItemClickListener<RightsDetailEntity>

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

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        var bean = mList[position]
        holder.id_tv_cards_name?.text="${bean.brand}${bean.goodsName}${bean.category}"
        holder.id_tv_cagte_name?.text="${bean.category}"
      //  holder.id_goods_icon?.setLoadImageUrl(bean.icon,false)
        holder.id_goods_yuan_jia?.text="${bean.goodsName}"
        holder.id_tv_card_discount?.text="会员专享${bean.costDiscount}折"
        holder.id_tv_card_price?.text="${bean.salePrice}"
        holder.id_tv_guanfang_price?.text="官方价 ¥${bean.originPrice}元"
        holder.id_tv_guanfang_price?.getPaint()?.setFlags(Paint.STRIKE_THRU_TEXT_FLAG) //中划线
        holder.id_ll_item?.setOnClickListener {
            listener.onItemClick(it, position, bean)
        }
    }

    override fun getItemCount(): Int {
        return mList.size
    }

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

    class ViewHolder : RecyclerView.ViewHolder {
        var id_ll_item: LinearLayout?
        var id_img_cards: RecycleImageView?
       // var id_goods_icon: RecycleImageView?
        var id_tv_cards_name: TextView?
        var id_goods_yuan_jia: TextView?
        var id_tv_card_discount: TextView?
        var id_tv_card_price: TextView?
        var id_tv_guanfang_price: TextView?
        var id_tv_cagte_name: TextView?


        constructor(
            itemView: View
        ) : super(itemView) {
            id_ll_item =
                itemView.findViewById<LinearLayout>(R.id.id_ll_item)
            id_img_cards = itemView.findViewById<RecycleImageView>(R.id.id_img_cards)
          //  id_goods_icon = itemView.findViewById<TextView>(R.id.id_goods_icon)
            id_tv_cards_name = itemView.findViewById<TextView>(R.id.id_tv_cards_name)
            id_goods_yuan_jia = itemView.findViewById<TextView>(R.id.id_goods_yuan_jia)
            id_tv_card_discount = itemView.findViewById<TextView>(R.id.id_tv_card_discount)
            id_tv_card_price = itemView.findViewById<TextView>(R.id.id_tv_card_price)
            id_tv_guanfang_price = itemView.findViewById<TextView>(R.id.id_tv_guanfang_price)
            id_tv_cagte_name = itemView.findViewById<TextView>(R.id.id_tv_cagte_name)


        }
    }
}