package com.adealink.weparty.profile.comp

import androidx.lifecycle.LifecycleOwner
import com.adealink.frame.util.onClick
import com.adealink.weparty.commonui.ext.gone
import com.adealink.weparty.commonui.ext.show
import com.adealink.weparty.commonui.util.DragViewUtil
import com.adealink.weparty.module.profile.data.UserInfo
import com.adealink.weparty.profile.databinding.ActivityUserProfileBinding
import com.adealink.weparty.profile.dialog.CharmStarDialog

class ProfilePlaymateComp(
    lifecycleOwner: LifecycleOwner,
    private val userUid: String,
    private val binding: ActivityUserProfileBinding,
) : BaseProfileViewComp(lifecycleOwner, userUid) {

    override fun initView() {
        binding.vPlaymateCharm.root.onClick {
            showCharmStar()
        }
        DragViewUtil.registerDragAction(binding.vPlaymateCharm.root)
    }

    override fun observeViewModel() {
        profileViewModel.userInfoLD.observe(viewLifecycleOwner) {
            updateUI(it)
        }
    }

    override fun updateUI(userInfo: UserInfo?) {
        if (userInfo == null) {
            binding.vPlaymateCharm.root.gone()
            return
        }
        if (!userInfo.isPlaymate() || userInfo.rated == true) {
            //仅陪玩显示
            binding.vPlaymateCharm.root.gone()
            return
        }
        binding.vPlaymateCharm.root.show()
    }

    private fun showCharmStar() {
        CharmStarDialog().show(fragmentManager)
    }

}