package com.adealink.weparty.im.session.dialog

import android.widget.CompoundButton
import androidx.fragment.app.activityViewModels
import com.adealink.frame.base.fastLazy
import com.adealink.frame.mvvm.view.viewBinding
import com.adealink.frame.util.onClick
import com.adealink.weparty.commonui.widget.BottomDialogFragment
import com.adealink.weparty.im.R
import com.adealink.weparty.im.databinding.DialogSessionSettingBinding
import com.adealink.weparty.im.session.viewmodel.SessionViewModel
import com.adealink.weparty.im.viewmodel.IMViewModelFactory
import com.adealink.weparty.module.profile.ProfileModule

class SessionSettingDialog : BottomDialogFragment(R.layout.dialog_session_setting) {

    private val binding by viewBinding(DialogSessionSettingBinding::bind)

    private val sessionViewModel by activityViewModels<SessionViewModel> { IMViewModelFactory() }
    private val profileViewModel by fastLazy { ProfileModule.getProfileViewModel(requireActivity()) }

    override fun initViews() {
        super.initViews()
        binding.vMuteSwitch.setOnCheckedChangeListener(object: CompoundButton.OnCheckedChangeListener{
            override fun onCheckedChanged(
                buttonView: CompoundButton?,
                isChecked: Boolean
            ) {
                sessionViewModel.setSessionMute(isChecked)
            }
        })
        binding.clMark.onClick {

        }
        binding.clBlack.onClick {

        }
        binding.clReport.onClick {

        }
    }

    override fun observeViewModel() {
        super.observeViewModel()
        sessionViewModel.isSessionMuteLD.observe(viewLifecycleOwner){
            updateMute(it)
        }
    }

    private fun updateMute(mute:Boolean){
        binding.vMuteSwitch.isChecked = mute
    }
}