package com.ym.game.adapter

import android.content.Context
import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.ym.xynt.R
import com.ym.library.base.BaseRecyclerAdapter
import com.ym.library.listener.OnRecycleItemClickListener
import com.ym.library.module.WithdrawEntity

/**
 *Craeted by ${junqi.li}
 *Craeted by 2020/8/26
 */
class WithdrawAdapter :
    BaseRecyclerAdapter<WithdrawEntity, WithdrawAdapter.WithdrawViewHodler> {

    private var context: Context? = null
    private var listener: OnRecycleItemClickListener<WithdrawEntity>? = null
    private var mSelectPosition: Int = -1

    constructor(
        context: Context?,
        listener: OnRecycleItemClickListener<WithdrawEntity>?
    ) : super() {
        this.context = context
        this.listener = listener
    }

    override fun getItemCount(): Int {
        return mList.size
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): WithdrawViewHodler {
        return WithdrawViewHodler(
            LayoutInflater.from(context).inflate(
                R.layout.item_user_withdraw,
                parent,
                false
            )
        )
    }

    override fun onBindViewHolder(holder: WithdrawViewHodler, position: Int) {
        if (mList.size > 0) {
            holder.tvText.text = "${mList[position].cashStr}${mList[position].unit}"
            val data = mList[position]
            /*if (data.cash == 0.3) {
                holder.ivNewerOnly.visibility = View.VISIBLE
            } else {
                holder.ivNewerOnly.visibility = View.GONE
            }*/
            if (data.ifUse == 1) {
                holder.ivNewerOnly.visibility = View.VISIBLE
//                holder.ivAlreadyCashed.visibility = View.VISIBLE
                holder.ivNewerOnly.setImageResource(R.drawable.icon_item_yitixian)
//                holder.ivAlreadyCashed.visibility = View.VISIBLE
                holder.layoutRoot.setBackgroundResource(R.drawable.shape_user_item_fbffe6_r6_bg)
                holder.tvText.setTextColor(Color.parseColor("#999999"))
            } else {
                // type "1 新人提现 2 打卡提现  3大额提现  4 福利专享 5 订单提现"
                if (data.type == 3) {
                    holder.ivNewerOnly.visibility = View.GONE

                } else {
                    holder.ivNewerOnly.visibility = View.VISIBLE
                    when(data.type) {
                        2 -> holder.ivNewerOnly.setBackgroundResource(R.drawable.icon_daka_jiaobiao)
                        3 -> holder.ivNewerOnly.visibility = View.GONE
                        4->holder.ivNewerOnly.setBackgroundResource(R.drawable.icon_fuli_jiaobiao)
                        10 -> holder.ivNewerOnly.setBackgroundResource(R.drawable.icon_meimeng_jiaobiao)
                        11 -> holder.ivNewerOnly.setBackgroundResource(R.drawable.icon_guaka_jiaobiao)
                    }
                }

                if (position == mSelectPosition) {
                    holder.layoutRoot.setBackgroundResource(R.drawable.icon_fragment_withdraw_selected)
                } else {
                    holder.layoutRoot.setBackgroundResource(R.drawable.icon_fragment_withdraw_select)
                }
            }
        }



        holder.itemView.setOnClickListener {
            listener?.onItemClick(it, position, mList[position])
        }

    }

    fun setSelectPosition() {
        mSelectPosition = -1
    }

    fun setSelectPosition(pos: Int) {
        mSelectPosition = pos
    }

    fun getSelectPosition(): Int {
        return mSelectPosition
    }


    class WithdrawViewHodler : RecyclerView.ViewHolder {
        var tvText: TextView
        var ivNewerOnly: ImageView
        var layoutRoot: RelativeLayout


        constructor(itemView: View) : super(itemView) {
            tvText = itemView.findViewById(R.id.tv_adapter_item_text)
            ivNewerOnly = itemView.findViewById(R.id.iv_adapter_item_tip_newer_only)
            layoutRoot = itemView.findViewById(R.id.layout_adapter_item_root)
        }
    }
}