package com.adealink.weparty.profile.comp

import androidx.lifecycle.LifecycleOwner
import com.adealink.frame.base.fastLazy
import com.adealink.frame.mvvm.view.ViewComponent
import com.adealink.frame.mvvm.viewmodel.activityViewModels
import com.adealink.weparty.module.profile.ProfileModule
import com.adealink.weparty.module.profile.data.UserInfo
import com.adealink.weparty.profile.viewmodel.ProfileViewModel
import com.adealink.weparty.profile.viewmodel.ProfileViewModelFactory

abstract class BaseProfileViewComp(
    lifecycleOwner: LifecycleOwner,
    private val userUid: String
) : ViewComponent(lifecycleOwner) {

    val isSelf by fastLazy { userUid == ProfileModule.getMyUid() }
    val profileViewModel by activityViewModels<ProfileViewModel> { ProfileViewModelFactory() }

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


    open fun initView() {}
    open fun observeViewModel() {}

    open fun loadData() {
        //使用缓存，快速展示
        updateUI(ProfileModule.getCacheUserInfo(uid = userUid))
    }

    open fun updateUI(userInfo: UserInfo?) {}

}