package com.zxbw.modulemain.box.adapter

import android.content.Context
import android.text.TextUtils
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.box.LotteryEntity
import com.zxhl.cms.widget.RecycleImageView


class BoxResultAdapter : BaseRecyclerAdapter<LotteryEntity, BoxResultAdapter.ViewHolder> {
    private var mContext: Context? = null

    constructor(
        content: Context?,
    ) : super() {
        mContext = content
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        var bean = mList[position]
        holder.id_box_result_goods_name?.text = bean.productName
        holder.id_tv_box_result_goods_pinzhi?.text = bean.cateName

        if (TextUtils.equals(bean.goodsLevel, "0")) {
            holder.id_tv_box_result_goods_pinzhi?.setBackgroundResource(R.drawable.shape_putong_bg_left_r10)
        } else if (TextUtils.equals(bean.goodsLevel, "1")) {
            holder.id_tv_box_result_goods_pinzhi?.setBackgroundResource(R.drawable.shape_xiyou_bg_left_r10)
        } else if (TextUtils.equals(bean.goodsLevel, "2")) {
            holder.id_tv_box_result_goods_pinzhi?.setBackgroundResource(R.drawable.shape_shishi_bg_left_r10)
        } else if (TextUtils.equals(bean.goodsLevel, "3")) {
            holder.id_tv_box_result_goods_pinzhi?.setBackgroundResource(R.drawable.shape_chuanshuo_bg_left_r10)
        }
        holder.id_box_result_goods_img?.setLoadImageUrl(bean.mainImage, false)
    }

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

    class ViewHolder : RecyclerView.ViewHolder {
        var id_ll_box_result: LinearLayout?
        var id_box_result_goods_img: RecycleImageView?
        var id_tv_box_result_goods_pinzhi: TextView?
        var id_box_result_goods_name: TextView?
        var id_box_result_goods_price: TextView?

        constructor(
            itemView: View
        ) : super(itemView) {
            id_ll_box_result = itemView.findViewById<LinearLayout>(R.id.id_ll_box_result)
            id_box_result_goods_img =
                itemView.findViewById<RecycleImageView>(R.id.id_box_result_goods_img)
            id_tv_box_result_goods_pinzhi =
                itemView.findViewById<TextView>(R.id.id_tv_box_result_goods_pinzhi)
            id_box_result_goods_name =
                itemView.findViewById<TextView>(R.id.id_box_result_goods_name)
            id_box_result_goods_price =
                itemView.findViewById<TextView>(R.id.id_box_result_goods_price)


        }
    }
}