package com.adealink.weparty.profile.me.comp

import androidx.lifecycle.LifecycleOwner
import com.adealink.frame.mvvm.view.ViewComponent
import com.adealink.frame.mvvm.viewmodel.activityViewModels
import com.adealink.frame.router.Router
import com.adealink.frame.util.onClick
import com.adealink.weparty.commonui.ext.show
import com.adealink.weparty.module.order.Order
import com.adealink.weparty.module.setting.Setting
import com.adealink.weparty.profile.databinding.LayoutMeFunctionBinding
import com.adealink.weparty.profile.viewmodel.ProfileViewModel

class MeFunctionCenterComp(
    lifecycleOwner: LifecycleOwner,
    val binding: LayoutMeFunctionBinding
) : ViewComponent(lifecycleOwner) {

    private val profileViewModel by activityViewModels<ProfileViewModel>()

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

    private fun initView() {
        binding.clOrder.onClick {
            goOrderList()
        }
        binding.clPlaymateOrder.onClick {
            goPlaymateOrderList()
        }
        binding.clHelpCenter.onClick {
            goHelpCenter()
        }
        binding.clSetting.onClick {
            goSetting()
        }
    }

    private fun observeViewModel() {
        profileViewModel.userInfoLD.observe(viewLifecycleOwner) {
//            if(it?.isPlaymate() == true){
//                binding.clPlaymateOrder.show()
//            }else{
//                binding.clPlaymateOrder.gone()
//            }
            binding.clPlaymateOrder.show()
        }
    }

    private fun goOrderList() {
        activity?.let { act ->
            Router.build(act, Order.List.PATH).start()
        }
    }

    private fun goPlaymateOrderList() {
        activity?.let { act ->
            Router.build(act, Order.PlaymateList.PATH).start()
        }
    }

    private fun goHelpCenter() {
        activity?.let { act ->
            Router.build(act, Setting.HelpCenter.PATH).start()
        }
    }

    private fun goSetting() {
        activity?.let { act ->
            Router.build(act, Setting.Setting.PATH).start()
        }
    }
}