package com.gamedog.vididin.features.withdraw.widget

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.LinearLayout
import com.ama.core.architecture.util.ResUtil
import com.gamedog.vididin.R
import com.gamedog.vididin.databinding.WithdrawItemViewBinding as ViewBinding


class WithDrawItemView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0
) : LinearLayout(context, attrs, defStyleAttr) {
    private var mItemIndex: Int = 0
    private var mIsSelected = false
    private var mCashNum: Float = 0F
    private var mBinding: ViewBinding


    init {
        mBinding = ViewBinding.inflate(LayoutInflater.from(context), this, true)
    }


    /**
     * For withdraw number in top area
     */
    fun setNumAndAction(itemIndex: Int, cashNum: Float, clickAction: (Int)->Unit) {
        mItemIndex = itemIndex
        mCashNum = cashNum
        mBinding.tvWithdrawNum.text = cashNum.toString()
        mBinding.root.setOnClickListener {
            clickAction.invoke(mItemIndex)
        }
    }


    /**
     * For bank item in bottom area
     */
    fun setIconAndText(iconRes: Int, textRes: Int, clickAction: ()->Unit) {
        mBinding.tvWithdrawNum.text = ResUtil.getString(textRes)
        mBinding.ivItemIcon.setImageResource(iconRes)
        mBinding.root.setOnClickListener {
            clickAction.invoke()
        }
    }

    fun setSelectedState(isSelected: Boolean) {
        mIsSelected = isSelected
        mBinding.root.setBackgroundResource(if (mIsSelected) R.drawable.withdraw_item_bg_selected else R.drawable.withdraw_item_bg_unselected)
    }

    fun getCashNum(): Float {
        return mCashNum
    }


}