package com.adealink.weparty.profile.edit

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.BindExtra
import com.adealink.frame.router.annotation.RouterUri
import com.adealink.frame.util.naviBarHeight
import com.adealink.frame.util.onClick
import com.adealink.frame.util.statusBarHeight
import com.adealink.weparty.commonui.BaseActivity
import com.adealink.weparty.commonui.ext.dp
import com.adealink.weparty.module.profile.Profile
import com.adealink.weparty.profile.databinding.ActivityEditProfileBinding
import com.adealink.weparty.profile.edit.comp.EditPersonComp
import com.adealink.weparty.profile.edit.comp.EditPhotoWallComp
import com.adealink.weparty.profile.edit.viewmodel.EditProfileViewModel
import com.adealink.weparty.profile.viewmodel.ProfileViewModel
import com.adealink.weparty.profile.viewmodel.ProfileViewModelFactory

@RouterUri(
    path = [Profile.EditProfile.PATH],
    desc = "编辑个人页"
)
class EditProfileActivity : BaseActivity() {

    @BindExtra(name = Profile.Common.EXTRA_UID)
    var userUid: String = ""

    private val binding by viewBinding(ActivityEditProfileBinding::inflate)
    private val profileViewModel by viewModels<ProfileViewModel> { ProfileViewModelFactory() }
    private val editViewModel by viewModels<EditProfileViewModel> { ProfileViewModelFactory() }

    override fun onBeforeCreate() {
        super.onBeforeCreate()
        Router.bind(this)
    }

    override fun initViews() {
        super.initViews()
        setContentView(binding.root)
        binding.topBar.updateLayoutParams<ConstraintLayout.LayoutParams> {
            topMargin = this@EditProfileActivity.statusBarHeight()
        }
        binding.clContent.setPadding(
            16.dp(), 0, 16.dp(), naviBarHeight() + 24.dp()
        )
        binding.btnSave.onClick {
            saveEdit()
        }
    }

    override fun initComponents() {
        super.initComponents()
        EditPhotoWallComp(this, binding.vPhotoWall).attach()
        EditPersonComp(this, binding.vPersonInfo).attach()
//        EditTalentComp(this, binding.vTalent).attach()
    }

    override fun loadData() {
        super.loadData()
    }

    private fun saveEdit() {
        showLoading()
//        profileViewModel.updateProfile(
//            newAvatarPath = avatarComp.getAvatarPath(),
//            newNickName = binding.etUserName.text?.toString(),
//            newGender = inputGender?.gender,
//            newBirthday = binding.etUserAge.text?.toString(),
//        ).observe(this) { rlt ->
//            dismissLoading()
//            when (rlt) {
//                is Rlt.Failed -> {
//                    showFailedToast(rlt)
//                }
//
//                is Rlt.Success<*> -> {
//                    showToast(getCompatString(APP_R.string.common_success))
//                    this@EditProfileActivity.finish()
//                }
//            }
//        }
    }

}