package com.swago.user

import android.view.View
import androidx.activity.viewModels
import com.alibaba.android.arouter.facade.annotation.Route
import com.swago.baseswago.activity.BaseXActivity
import com.swago.baseswago.constant.ARouteConstant
import com.swago.baseswago.dialog.ChoiceDialogFragment
import com.swago.baseswago.util.AppContext
import com.swago.baseswago.util.NoDoubleClickListener
import com.swago.baseswago.util.SwagoLoading
import com.swago.baseswago.util.UserInfo
import com.swago.user.databinding.ActivityModifyPwdBinding
import com.swago.user.vm.TaskVm

@Route(path = ARouteConstant.User.modifyPwd)
class ModifyPwdActivity : BaseXActivity<ActivityModifyPwdBinding>() {

    private val taskVm by viewModels<TaskVm>()

    override fun loadData() {

    }

    override fun initOther() {
        setBackView(binding.toolbar.ivBack)
        UserInfo.getUserInfo()?.let {
            if(it.is_password == 1){
                binding.tvCurrentPwd.visibility = View.VISIBLE
                binding.etCurrentPwd.visibility = View.VISIBLE
            }
        }
        binding.tvSave.setOnClickListener(object:NoDoubleClickListener(){
            override fun onClick() {
                ChoiceDialogFragment.newInstance(AppContext.getContext().resources.getString(R.string.do_you_confirm_change_pwd),AppContext.getContext().resources.getString(R.string.change_password)).apply {
                    this.sureFun = {
                        SwagoLoading.showLoadingDialog(this@ModifyPwdActivity)
                        val oldPwd = this@ModifyPwdActivity.binding.etCurrentPwd.text.toString()
                        val newPwd = this@ModifyPwdActivity.binding.etNewPwd.text.toString()
                        val confirmNewPwd = this@ModifyPwdActivity.binding.etConfirmNewPwd.text.toString()
                        taskVm.changePwd(oldPwd,newPwd,confirmNewPwd)
                    }
                }.show(supportFragmentManager,"ChoiceDialogFragment")
            }
        })
    }

    override fun initLiveData() {

    }
}