package com.adealink.weparty.wallet.recharge.fragment

import androidx.fragment.app.viewModels
import com.adealink.frame.mvvm.view.viewBinding
import com.adealink.frame.util.onClick
import com.adealink.weparty.commonui.BaseFragment
import com.adealink.weparty.module.wallet.data.Currency
import com.adealink.weparty.wallet.R
import com.adealink.weparty.wallet.databinding.FragmentRechargeBeanBinding
import com.adealink.weparty.wallet.recharge.dialog.ConvertCurrencyDialog
import com.adealink.weparty.wallet.viewmodel.WalletViewModel
import com.adealink.weparty.wallet.viewmodel.WalletViewModelFactory

class BeanExchangedFragment : BaseFragment(R.layout.fragment_recharge_bean) {

    private val binding by viewBinding(FragmentRechargeBeanBinding::bind)
    private val walletViewModel by viewModels<WalletViewModel> { WalletViewModelFactory() }

    override fun initViews() {
        super.initViews()

        // TODO: 需要判断提审版本
        binding.vBeanCard.btnWithdraw.onClick {
            withDraw()
        }

        binding.btnConvertCoin.onClick {
            convertToCoin()
        }
        binding.btnConvertDiamond.onClick {
            convertToDiamond()
        }
    }

    override fun observeViewModel() {
        super.observeViewModel()
        walletViewModel.beanLD.observe(viewLifecycleOwner) {

        }
    }

    private fun convertToCoin() {
        ConvertCurrencyDialog().apply {
            fromCurrency = Currency.BEAN
            toCurrency = Currency.COIN
        }.show(childFragmentManager, "ConvertCurrencyDialog")
    }

    private fun convertToDiamond() {
        ConvertCurrencyDialog().apply {
            fromCurrency = Currency.BEAN
            toCurrency = Currency.DIAMOND
        }.show(childFragmentManager, "ConvertCurrencyDialog")
    }

    private fun withDraw() {

    }
}