package com.adealink.weparty.share.qrcode.page

import androidx.fragment.app.viewModels
import com.adealink.frame.mvvm.view.viewBinding
import com.adealink.weparty.commonui.BaseFragment
import com.adealink.weparty.module.playmate.data.PlaymateCategoryData
import com.adealink.weparty.module.playmate.data.UserPlaymateCategoryData
import com.adealink.weparty.share.R
import com.adealink.weparty.share.databinding.FragmentSpecialQrCodeBinding
import com.adealink.weparty.share.qrcode.viewmodel.QRCodeViewModel
import com.adealink.weparty.share.viewmodel.ShareViewModelFactory

class SpecialQRCodeFragment : BaseFragment(R.layout.fragment_special_qr_code) {

    private val binding by viewBinding(FragmentSpecialQrCodeBinding::bind)
    private val qrCodeViewModel by viewModels<QRCodeViewModel>(ownerProducer = {
        parentFragment ?: this
    }, factoryProducer = { ShareViewModelFactory() })

    override fun initViews() {
        super.initViews()
    }

    override fun observeViewModel() {
        super.observeViewModel()
        qrCodeViewModel.currentCategoryLD.observe(this) {
            updatePanel(it)
        }
    }

    private fun updatePanel(data: UserPlaymateCategoryData?) {
        binding.etInputPrice.setText(data?.price?.toString() ?: "")
    }

}