package com.zxbw.modulemain.adapter

import android.app.Activity
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.CouponsEntity
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 PhoneVouchersAdapter :
    BaseRecyclerAdapter<CouponsEntity, PhoneVouchersAdapter.ViewHolder> {
    private var mContext: Activity? = null
    private val listener: OnRecycleItemClickListener<CouponsEntity>

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

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        var bean = mList[position]
        holder.id_tv_cards_name?.text = "${bean.amount}元话费券"
        holder.id_tv_guanfang_price?.text = bean.desc
        holder.id_goods_yuan_jia?.text = "${bean.amount}"

        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_phone_voucher, 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)


        }
    }
}