package com.zxhl.main.page.adapter

import android.content.Context
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.zxhl.cms.AppContext
import com.zxhl.cms.common.base.BaseRecyclerAdapter
import com.zxhl.cms.net.model.box.GoodList
import com.zxhl.cms.utils.JumpUtils
import com.zxhl.cms.widget.RecycleImageView
import com.zxhl.main.R

class ItemGoodsAdapter : BaseRecyclerAdapter<GoodList, ItemGoodsAdapter.ViewHolder> {
    private var mContext: Context? = null
    private var boxId:String?=""
    constructor(
        content: Context?,
        boxId:String?
    ) : super() {
        mContext = content
        this.boxId=boxId
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        var bean = mList[position]
        holder.item_goods_img?.setLoadImageUrl(bean.mainImage, false)
        holder.item_goods_name?.text = bean.productName
        holder.item_goods_price?.text = "$${bean.salePriceStr}"
        holder.id_tv_item_layout?.setOnClickListener {
            JumpUtils.goodsDetailJump(boxId)
        }
    }


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

    class ViewHolder : RecyclerView.ViewHolder {
        var item_goods_img: RecycleImageView?
        var item_goods_name: TextView?
        var item_goods_price: TextView?
        var id_tv_item_layout: LinearLayout?

        constructor(
            itemView: View
        ) : super(itemView) {
            item_goods_img = itemView.findViewById<RecycleImageView>(R.id.id_img_goods)
            item_goods_name = itemView.findViewById<TextView>(R.id.id_tv_goods_name)
            item_goods_price = itemView.findViewById<TextView>(R.id.id_tv_goods_price)
            id_tv_item_layout = itemView.findViewById<LinearLayout>(R.id.id_tv_item_layout)

        }
    }
}