package com.zxhl.main.page.adapter

import android.content.Context
import android.text.TextUtils
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.zxhl.cms.AppContext
import com.zxhl.cms.common.base.BaseRecyclerAdapter
import com.zxhl.cms.net.SettingPreference
import com.zxhl.cms.net.model.box.DepotEntity
import com.zxhl.cms.widget.RecycleImageView
import com.zxhl.main.R

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

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

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        var bean = mList[position]
        holder?.item_img_goods?.setLoadImageUrl(bean.products?.mainImage, false)
        holder?.item_tv_good_name?.text = bean.products?.productName
        holder?.item_tv_good_price?.text = bean.amountSpent
        holder?.item_recover_price?.text = bean.recoverPriceStr
        if(TextUtils.equals(SettingPreference.getRecoveType(),"1")){
            holder.id_img_icon?.setImageResource(R.drawable.icon_mobi)
        }else{
            holder.id_img_icon?.setImageResource(R.drawable.icon_jinbi)
        }

    }


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

    class ViewHolder : RecyclerView.ViewHolder {

        var item_img_goods: RecycleImageView?
        var item_tv_good_name: TextView?
        var item_tv_good_price: TextView?
        var item_recover_price: TextView?
        var id_img_icon: ImageView?

        constructor(
            itemView: View
        ) : super(itemView) {

            item_tv_good_name = itemView.findViewById<TextView>(R.id.id_goods_name)
            item_tv_good_price = itemView.findViewById<TextView>(R.id.id_tv_good_price)
            item_img_goods = itemView.findViewById<RecycleImageView>(R.id.id_goods_img)
            item_recover_price = itemView.findViewById<TextView>(R.id.id_tv_recover_price)
            id_img_icon = itemView.findViewById<ImageView>(R.id.id_img_icon)
        }
    }
}