package com.zxbw.modulemain.adapter

import android.app.Activity
import android.content.Intent
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.zxbw.modulemain.activity.XymhCardDetailActivity
import com.zxbw.modulemain.activity.XymhShopOrderActivity
import com.zxhl.cms.AppContext
import com.zxhl.cms.common.base.BaseRecyclerAdapter
import com.zxhl.cms.net.model.qy.SkillGoodsEntity
import com.zxhl.cms.utils.JumpUtils
import com.zxhl.cms.widget.RecycleImageView

class MoreDiscountAdapter : BaseRecyclerAdapter<SkillGoodsEntity, MoreDiscountAdapter.ViewHolder> {
    private var mContext: Activity? = null

    constructor(
        content: Activity?
    ) : super() {
        mContext = content
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        var bean = mList[position]

        if (!TextUtils.equals(bean.goodsType, "99")) {
            holder.id_img_member_bg?.setLoadImageUrl(bean.icon, false)
            holder.id_tv_name?.text =
                "${bean.card?.brand}${bean.card?.category}${bean.card?.goodsName}"
            holder.id_tv_sale_price?.text = "${bean.card?.originPrice}"
            holder.id_tv_activity_price?.text = "¥${bean.card?.salePrice}"
        } else {
            holder.id_img_member_bg?.setLoadImageUrl(bean.goods?.mainImage, false)
            holder.id_tv_name?.text = "${bean.goods?.productName}"
            holder.id_tv_sale_price?.text = "${bean.goods?.originalPriceDb}"
            holder.id_tv_activity_price?.text = "¥${bean.card?.salePrice}"
        }

        holder.id_ll_item?.setOnClickListener {
            if (TextUtils.equals(bean.goodsType, "50")) {
                JumpUtils.RightsDetailJump(bean.card?.brand, bean.card?.icon)
            } else if (TextUtils.equals(bean.goodsType, "51")) {
                val intent = Intent(mContext, XymhCardDetailActivity::class.java)
                intent.putExtra("cardbean", bean.card)
                mContext?.startActivity(intent)
            } else if (TextUtils.equals(bean.goodsType, "99")) {
                //实物商品
                var mChoosList: MutableList<String> = ArrayList()
                mChoosList.clear()
                mChoosList.add(bean.goods?.id.toString())
                val intent = Intent(mContext, XymhShopOrderActivity::class.java)
                intent.putStringArrayListExtra(
                    "stringList",
                    mChoosList as java.util.ArrayList<String>?
                )
                mContext?.startActivity(intent)
            }
        }
    }

//    override fun getItemCount(): Int {
//        return 9
//    }

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

    class ViewHolder : RecyclerView.ViewHolder {
        var id_ll_item: LinearLayout?
        var id_img_member_bg: RecycleImageView?
        var id_tv_name: TextView?
        var id_tv_sale_price: TextView?
        var id_tv_activity_price: TextView?

        constructor(
            itemView: View
        ) : super(itemView) {
            id_ll_item = itemView.findViewById(R.id.id_ll_item)
            id_img_member_bg = itemView.findViewById(R.id.id_img_member_bg)
            id_tv_name = itemView.findViewById(R.id.id_tv_name)
            id_tv_sale_price = itemView.findViewById(R.id.id_tv_sale_price)
            id_tv_activity_price = itemView.findViewById(R.id.id_tv_activity_price)

        }
    }
}