package com.adealink.weparty.wallet.comp

import androidx.lifecycle.LifecycleOwner
import com.adealink.frame.mvvm.view.ViewComponent
import com.adealink.frame.mvvm.viewmodel.activityViewModels
import com.adealink.frame.router.Router
import com.adealink.frame.util.onClick
import com.adealink.weparty.commonui.ext.gone
import com.adealink.weparty.commonui.ext.show
import com.adealink.weparty.module.profile.ProfileModule
import com.adealink.weparty.module.wallet.Wallet
import com.adealink.weparty.module.wallet.data.Currency
import com.adealink.weparty.util.formatNumberStr
import com.adealink.weparty.wallet.databinding.LayoutWalletIncomeBinding
import com.adealink.weparty.wallet.viewmodel.WalletViewModel
import com.adealink.weparty.wallet.viewmodel.WalletViewModelFactory

class MyIncomeComp(
    lifecycleOwner: LifecycleOwner,
    val binding: LayoutWalletIncomeBinding
) : ViewComponent(lifecycleOwner) {

    private val viewModel by activityViewModels<WalletViewModel> { WalletViewModelFactory() }

    override fun onCreate() {
        super.onCreate()
        initView()
        observeViewModel()
    }

    private fun initView() {
        binding.btnTopUpCoin.onClick {
            goBeanDetail()
        }
    }

    private fun observeViewModel() {
        viewModel.availableBeanLD.observe(viewLifecycleOwner) {
            binding.tvBean.text = formatNumberStr(it)
        }
    }

    private fun goBeanDetail() {
        val act = activity ?: return
        Router.build(act, Wallet.Recharge.PATH)
            .putExtra(Wallet.Common.EXTRA_CURRENCY, Currency.BEAN.type)
            .start()
    }

}