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.util.onClick
import com.adealink.weparty.util.formatNumberStr
import com.adealink.weparty.wallet.databinding.LayoutWalletBalanceBinding
import com.adealink.weparty.wallet.viewmodel.WalletViewModel
import com.adealink.weparty.wallet.viewmodel.WalletViewModelFactory

class MyBalanceComp(
    lifecycleOwner: LifecycleOwner,
    val binding: LayoutWalletBalanceBinding
) : ViewComponent(lifecycleOwner) {

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

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

    private fun initView() {
        binding.btnTopUpCoin.onClick {
            topUpCoin()
        }
        binding.btnTopUpDiamond.onClick {
            topUpDiamond()
        }
    }

    private fun observeViewModel() {
        viewModel.coinLD.observe(viewLifecycleOwner) {
            binding.tvCoin.text = formatNumberStr(it)
        }
        viewModel.diamondLD.observe(viewLifecycleOwner) {
            binding.tvDiamond.text = formatNumberStr(it)
        }
    }

    private fun loadData() {
        viewModel.getWalletData()
    }

    private fun topUpCoin() {

    }

    private fun topUpDiamond() {

    }
}