package com.adealink.weparty.playmate.setting

import androidx.activity.viewModels
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.updateLayoutParams
import com.adealink.frame.mvvm.view.viewBinding
import com.adealink.frame.router.Router
import com.adealink.frame.router.annotation.RouterUri
import com.adealink.weparty.commonui.BaseActivity
import com.adealink.weparty.commonui.toast.util.showFailedToast
import com.adealink.weparty.module.playmate.Playmate
import com.adealink.weparty.playmate.databinding.ActivityPlaymateOrderSettingBinding
import com.adealink.weparty.playmate.setting.comp.OrderSayWelcomeComp
import com.adealink.weparty.playmate.setting.comp.OrderTimeRangeComp
import com.adealink.weparty.playmate.setting.comp.OrderWeekDayComp
import com.adealink.weparty.playmate.setting.viewmodel.OrderSettingViewModel
import com.adealink.weparty.playmate.viewmodel.PlaymateViewModelFactory
import com.adealink.weparty.util.applyImmersive

@RouterUri(path = [Playmate.OrderSetting.PATH], desc = "接单设置")
class PlaymateOrderSettingActivity : BaseActivity() {

    private val binding by viewBinding(ActivityPlaymateOrderSettingBinding::inflate)

    private val viewModel by viewModels<OrderSettingViewModel> { PlaymateViewModelFactory() }
    override fun onBeforeCreate() {
        super.onBeforeCreate()
        Router.bind(this)
    }

    override fun initViews() {
        super.initViews()
        setContentView(binding.root)
        applyImmersive { top ->
            binding.topBar.updateLayoutParams<ConstraintLayout.LayoutParams> {
                topMargin = top
            }
        }
    }

    override fun initComponents() {
        super.initComponents()
        OrderTimeRangeComp(this, binding.vTimeRange).attach()
        OrderWeekDayComp(this, binding.vWeekDay).attach()
        OrderSayWelcomeComp(this, binding.vSayWelcome).attach()
    }

    override fun loadData() {
        super.loadData()
        viewModel.getOrderSetting().observe(this) {
            showFailedToast(it)
        }
    }


}