package com.adealink.weparty.profile.edit.comp

import androidx.lifecycle.LifecycleOwner
import com.adealink.frame.aab.util.getCompatString
import com.adealink.frame.mvvm.view.ViewComponent
import com.adealink.frame.mvvm.viewmodel.activityViewModels
import com.adealink.frame.util.onClick
import com.adealink.weparty.module.profile.data.VoiceData
import com.adealink.weparty.profile.R
import com.adealink.weparty.profile.databinding.LayoutEditProfilePersonTalentBinding
import com.adealink.weparty.profile.edit.dialog.EditTalentVoiceDialog
import com.adealink.weparty.profile.viewmodel.ProfileViewModel
import com.adealink.weparty.profile.viewmodel.ProfileViewModelFactory
import com.adealink.weparty.R as APP_R

class EditTalentComp(
    lifecycleOwner: LifecycleOwner,
    private val binging: LayoutEditProfilePersonTalentBinding
) : ViewComponent(lifecycleOwner) {

    companion object {
        private const val SOURCE_TAG = "EditTalentComp"
    }

    private val profileViewModel by activityViewModels<ProfileViewModel> { ProfileViewModelFactory() }

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

    private fun initView() {
        binging.clVoice.onClick {
            editIntro()
        }
    }

    private fun observeViewModel() {
        profileViewModel.myUserInfoLD.observe(viewLifecycleOwner) { userInfo ->
            val userVoice = userInfo?.userVoiceEdit
            if (userVoice != null && userVoice.isDisplay()) {
                binging.tvVoice.text = getCompatString(R.string.profile_edit_voice_not_empty)
            } else if (userVoice != null && userVoice.isUnderReview()) {
                binging.tvVoice.text = getCompatString(APP_R.string.common_under_review)
            } else {
                binging.tvVoice.text = null
            }
        }
    }

    private fun editIntro() {
        EditTalentVoiceDialog().apply {
            setVoice(profileViewModel.myUserInfoLD.value?.userVoiceEdit)
            setCallback(object : EditTalentVoiceDialog.ITalentVoiceCallback {
                override fun onEditVoice(voice: VoiceData?) {

                }
            })
        }.show(fragmentManager, "EditVoice")
    }

}