package com.adealink.weparty.playmate.setting.comp

import androidx.lifecycle.LifecycleOwner
import com.adealink.frame.mvvm.viewmodel.viewModels
import com.adealink.frame.util.onClick
import com.adealink.weparty.commonui.BaseViewComponent
import com.adealink.weparty.playmate.databinding.LayoutPlaymateOrderSettingWeekDayBinding
import com.adealink.weparty.playmate.setting.dialog.WeekDayDialog
import com.adealink.weparty.playmate.setting.viewmodel.OrderSettingViewModel
import com.adealink.weparty.playmate.viewmodel.PlaymateViewModelFactory
import com.adealink.weparty.util.formatWeekdays

class OrderWeekDayComp(
    lifecycleOwner: LifecycleOwner,
    val binding: LayoutPlaymateOrderSettingWeekDayBinding
) : BaseViewComponent(lifecycleOwner) {
    private val viewModel by viewModels<OrderSettingViewModel> { PlaymateViewModelFactory() }

    override fun initViews() {
        super.initViews()
        binding.root.onClick {
            selectWeekDay()
        }
    }

    override fun observeViewModel() {
        super.observeViewModel()
        viewModel.weekDayLD.observe(viewLifecycleOwner) { days ->
            binding.tvDesc.text = formatWeekdays(days)
        }
    }

    private fun selectWeekDay() {
        WeekDayDialog().show(fragmentManager, "WeekDayDialog")
    }
}