package com.zxbw.modulemain.adapter

import android.app.Activity
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
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.widget.RecycleImageView


class ItemVipOrderAdapter :
    BaseRecyclerAdapter<RightsDetailEntity, ItemVipOrderAdapter.ViewHolder> {
    private var mContext: Activity? = null
    private var mType: String? = ""

    constructor(
        content: Activity?,
        type: String?
    ) : super() {
        mContext = content
        mType = type
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        var bean = mList[position]
        holder.id_tv_vip_goods_price?.text = "¥${bean.salePrice}"
        if (mType.equals("8080")) {
            if (mContext?.isDestroyed != true) {
                holder?.id_img_rights_bg?.setImageResource(R.drawable.img_vip_rights_bg)
                Glide.with(mContext!!).asGif().load(R.drawable.img_gif_huafei)
                    .into(holder.id_img_rights_icon!!)
            }
            //1 充值中 2 充值成功 4 充值失败
            if (bean.status.equals("2")){
                holder.id_tv_huafei_desc?.text="充值成功"
            }else if (bean.status.equals("4")){
                holder.id_tv_huafei_desc?.text="充值异常,请联系客服查询订单状态"
            }else{
                holder.id_tv_huafei_desc?.text="72小时内到账"
            }
            holder.id_tv_vip_goods_name?.text = bean.goodsName
            holder.id_tv_huafei_desc?.visibility = View.VISIBLE
            holder.id_tv_vip_goods_num?.visibility = View.GONE
        } else {
            if (mContext?.isDestroyed != true) {
                Glide.with(mContext!!).load(bean.bgImage).placeholder(R.drawable.img_vip_rights_bg)
                    .into(holder?.id_img_rights_bg!!)

                Glide.with(mContext!!).load(bean.icon)
                    .into(holder?.id_img_rights_icon!!)
            }
            holder.id_tv_vip_goods_name?.text = "${bean.brand} ${bean.category} ${bean.goodsName}"

            holder.id_tv_huafei_desc?.visibility = View.GONE
            holder.id_tv_vip_goods_num?.visibility = View.VISIBLE
        }
    }


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

    class ViewHolder : RecyclerView.ViewHolder {
        var id_img_rights_bg: ImageView?
        var id_img_rights_icon: ImageView?
        var id_tv_vip_goods_name: TextView?
        var id_tv_vip_goods_price: TextView?
        var id_tv_vip_goods_num: TextView?
        var id_tv_huafei_desc: TextView?

        constructor(
            itemView: View
        ) : super(itemView) {
            id_img_rights_bg = itemView.findViewById<ImageView>(R.id.id_img_rights_bg)
            id_img_rights_icon = itemView.findViewById<ImageView>(R.id.id_img_rights_icon)
            id_tv_vip_goods_name = itemView.findViewById<TextView>(R.id.id_tv_vip_goods_name)
            id_tv_vip_goods_price = itemView.findViewById<TextView>(R.id.id_tv_vip_goods_price)
            id_tv_vip_goods_num = itemView.findViewById<TextView>(R.id.id_tv_vip_goods_num)
            id_tv_huafei_desc = itemView.findViewById<TextView>(R.id.id_tv_huafei_desc)
        }
    }

}