package com.zxhl.cms.pay


import android.app.Activity
import android.content.Context
import android.text.TextUtils
import android.util.Log
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.zxhl.cms.AppContext
import com.zxhl.cms.R
import com.zxhl.cms.common.base.BaseRecyclerAdapter
import com.zxhl.cms.net.model.box.PayFun
import com.zxhl.cms.net.model.video.MemberEntity
import com.zxhl.cms.utils.OnRecycleItemClickListener
import com.zxhl.cms.utils.Utils


/**
 * Created by gaoleichao on 2021/8/30
 */
class PaymentFunAdapter :
    BaseRecyclerAdapter<PayFun, PaymentFunAdapter.PayFunHolder> {
    private var mActivity: Activity? = null
    private var position = -1

    private val mListener: OnRecycleItemClickListener<PayFun>

    constructor(
        activity: Activity,
        mListener: OnRecycleItemClickListener<PayFun>
    ) : super() {
        this.mActivity = activity
        this.mListener = mListener
    }


    fun setPosition(pos: Int) {
        position = pos
        notifyDataSetChanged()
    }


    override fun onCreateViewHolder(p0: ViewGroup, p1: Int): PayFunHolder {
        return PayFunHolder(
            LayoutInflater.from(p0.context).inflate(R.layout.item_payment_fun_view, p0, false)
        )
    }

    override fun onBindViewHolder(holder: PayFunHolder, pos: Int) {
        val data = mList[pos]
        if (pos == position) {
            holder.mPayCheck.setImageResource(R.drawable.icon_xuanzhong)
        } else {
            holder.mPayCheck.setImageResource(R.drawable.icon_xuanzhong_default)
        }
        if (mActivity != null && mActivity?.isFinishing == false) {
            Glide.with(mActivity!!).load(data.icon).into(holder.mPayIcon)
        }
        holder.mPayName.text = data.title
        if (data.open == 1) {
            holder.mItemView.visibility = View.VISIBLE
        } else {
            holder.mItemView.visibility = View.GONE
        }
        holder.mItemView.setOnClickListener {
            mListener.onItemClick(it, pos, data)
        }

    }

    inner class PayFunHolder : RecyclerView.ViewHolder {
        var mItemView: LinearLayout
        var mPayIcon: ImageView
        var mPayName: TextView
        var mPayCheck: ImageView

        constructor(itemView: View) : super(itemView) {
            mItemView = itemView.findViewById<LinearLayout>(R.id.id_item_ll_pay_view)
            mPayIcon = itemView.findViewById<ImageView>(R.id.id_item_img_pay_icon)
            mPayName = itemView.findViewById<TextView>(R.id.id_item_tv_pay_name)
            mPayCheck = itemView.findViewById<ImageView>(R.id.id_item_img_check)
        }
    }
}