package com.zxbw.modulemain.adapter

import android.app.Activity
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.LinearLayout
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.bumptech.glide.request.RequestOptions
import com.zxbw.modulemain.R
import com.zxhl.cms.AppContext
import com.zxhl.cms.common.base.BaseRecyclerAdapter
import com.zxhl.cms.net.model.qy.JgqQyEntity
import com.zxhl.cms.utils.OnRecycleItemClickListener
import kotlinx.android.synthetic.main.activity_layout_rights_detail.*


class JgqQyAdapter : BaseRecyclerAdapter<JgqQyEntity, JgqQyAdapter.ViewHolder> {
    private var mContext: Activity? = null
    private val listener: OnRecycleItemClickListener<JgqQyEntity>

    constructor(
        content: Activity?,
        listener: OnRecycleItemClickListener<JgqQyEntity>
    ) : super() {
        mContext = content
        this.listener = listener
    }

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

        Glide.with(mContext!!).load(bean.icon)
            .apply(RequestOptions.bitmapTransform(CircleCrop()))
            .into(holder?.id_icon!!)
        holder.id_name?.text = bean.brand
        if(bean.maxDiscount.isNullOrEmpty()||bean.maxDiscount.equals("0")){
            holder.id_tv_discount_value?.visibility = View.INVISIBLE
        }else{
            holder.id_tv_discount_value?.visibility = View.VISIBLE
            holder.id_tv_discount_value?.text = "${bean.maxDiscount}折"
        }
        holder.id_rl_qy_item_view?.setOnClickListener {
            listener.onItemClick(it, position, bean)
        }
    }

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

    class ViewHolder : RecyclerView.ViewHolder {
        var id_rl_qy_item_view: RelativeLayout?
        var id_icon: ImageView?
        var id_name: TextView?
        var id_tv_discount_value: TextView?

        constructor(
            itemView: View
        ) : super(itemView) {
            id_rl_qy_item_view = itemView.findViewById<RelativeLayout>(R.id.id_rl_qy_item_view)
            id_icon =
                itemView.findViewById<ImageView>(R.id.id_img_qy_icon)
            id_name =
                itemView.findViewById<TextView>(R.id.id_tv_qy_name)
            id_tv_discount_value =
                itemView.findViewById<TextView>(R.id.id_tv_discount_value)


        }
    }
}