package com.adealink.weparty.wallet.recharge.adapter

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.ViewGroup
import com.adealink.frame.util.onClick
import com.adealink.weparty.commonui.commonSelectedDrawable
import com.adealink.weparty.commonui.recycleview.adapter.BindingViewHolder
import com.adealink.weparty.commonui.recycleview.adapter.multitype.ItemViewBinder
import com.adealink.weparty.module.wallet.data.Currency
import com.adealink.weparty.wallet.databinding.LayoutRechargeItemBinding
import com.adealink.weparty.wallet.recharge.data.RechargeItemData
import com.adealink.weparty.R as APP_R

class RechargeItemViewBinder(
    val currency: Currency,
    val onItemSelected: (item: RechargeItemData) -> Unit
) :
    ItemViewBinder<RechargeItemData, BindingViewHolder<LayoutRechargeItemBinding>>() {
    override fun onCreateViewHolder(
        inflater: LayoutInflater,
        parent: ViewGroup
    ): BindingViewHolder<LayoutRechargeItemBinding> {
        return BindingViewHolder(
            LayoutRechargeItemBinding.inflate(
                inflater,
                parent,
                false
            )
        )
    }

    @SuppressLint("SetTextI18n")
    override fun onBindViewHolder(
        holder: BindingViewHolder<LayoutRechargeItemBinding>,
        item: RechargeItemData
    ) {
        holder.binding.root.onClick {
            onItemSelected.invoke(item)
        }
        when (currency) {
            Currency.BEAN -> {
                holder.binding.ivCurrency.setImageResource(APP_R.drawable.common_wallet_bean_32_ic)
            }

            Currency.COIN -> {
                holder.binding.ivCurrency.setImageResource(APP_R.drawable.common_wallet_coin_32_ic)
            }

            Currency.DIAMOND -> {
                holder.binding.ivCurrency.setImageResource(APP_R.drawable.common_wallet_diamond_32_ic)
            }
        }

        if (item.selected) {
            holder.binding.vBg.background = selectedDrawable
        } else {
            holder.binding.vBg.background = null
        }
        holder.binding.tvAmount.text = item.data.amount.toString()
        holder.binding.tvSpend.text = "IDR ${item.data.spend}"

    }

    companion object {
        private val selectedDrawable = commonSelectedDrawable()
    }


}