package com.adealink.weparty.profile.comp

import android.annotation.SuppressLint
import androidx.lifecycle.LifecycleOwner
import com.adealink.frame.util.onClick
import com.adealink.weparty.module.im.IMModule
import com.adealink.weparty.module.profile.data.UserInfo
import com.adealink.weparty.profile.databinding.LayoutUserProfileHeaderBinding
import com.adealink.weparty.profile.dialog.EvaluateDialog

class ProfileHeaderComp(
    lifecycleOwner: LifecycleOwner,
    private val userUid: String,
    private val binding: LayoutUserProfileHeaderBinding,
) : BaseProfileViewComp(lifecycleOwner, userUid) {

    override fun initView() {
        binding.tvEvaluate.onClick {
            showEvaluateDialog()
        }
    }

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

    @SuppressLint("SetTextI18n")
    override fun updateUI(userInfo: UserInfo?) {
        binding.ivBg.setImageUrl(userInfo?.avatar)
        binding.tvName.text = userInfo?.nickName
        binding.tvUserId.text = "ID ${userInfo?.uid}"

        binding.vSound.setSoundUrl("")


        binding.tvName.onClick {
            val act = activity ?: return@onClick
            val uid = profileViewModel.userInfoLD.value?.uid ?: return@onClick
            IMModule.goSession(act, uid)
        }
    }

    private fun showEvaluateDialog() {
        EvaluateDialog().show(fragmentManager)
    }
}