package com.hongyegroup.cpt_auths.ui

import android.content.Intent
import android.os.Bundle
import androidx.lifecycle.MutableLiveData
import com.guadou.cs_cptservices.base.activity.YYBaseVDBActivity
import com.guadou.lib_baselib.base.vm.EmptyViewModel
import com.guadou.lib_baselib.bean.DataBindingConfig
import com.guadou.lib_baselib.utils.CommUtils
import com.guadou.lib_baselib.utils.KeyboardUtils
import com.hongyegroup.cpt_auths.BR
import com.hongyegroup.cpt_auths.R
import com.hongyegroup.cpt_auths.databinding.ActivityResetPasswordBinding

/**
 * 公用的页面 重置密码
 * 输入旧密码，新密码 更换密码
 * 输入新密码  忘记密码
 */
class ResetPasswordActivity : YYBaseVDBActivity<EmptyViewModel, ActivityResetPasswordBinding>() {

    private var isFromBusiness: Boolean = false
    private var isForgort: Boolean = false
    private val clickProxy by lazy { ClickProxy() }

    companion object {
        fun startInstance(isFromBusiness: Boolean, isForgort: Boolean) {
            val context = CommUtils.getContext()
            val intent = Intent(context, ResetPasswordActivity::class.java)
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            intent.putExtra("isFromBusiness", isFromBusiness)
            intent.putExtra("isForgort", isForgort)
            context.startActivity(intent)
        }
    }

    override fun getDataBindingConfig(): DataBindingConfig {
        return DataBindingConfig(R.layout.activity_reset_password)
            .addBindingParams(BR.click, clickProxy)
    }

    override fun getDataFromIntent(intent: Intent) {
        this.isFromBusiness = intent.getBooleanExtra("isFromBusiness", false)
        this.isForgort = intent.getBooleanExtra("isForgort", false)

        clickProxy.isShowOldBoxLD.value = !isForgort
    }

    override fun startObserve() {

    }

    override fun init(savedInstanceState: Bundle?) {

    }

    /**
     * DataBinding事件处理
     */
    inner class ClickProxy {

        //是否展示旧密码
        val isShowOldBoxLD: MutableLiveData<Boolean> = MutableLiveData()

        //旧密码
        val mOldPasswordLD: MutableLiveData<String> = MutableLiveData()

        //密码
        val mNewPasswordLD: MutableLiveData<String> = MutableLiveData()

        //确认密码
        val mConfirmPsdLD: MutableLiveData<String> = MutableLiveData()


        //执行登录校验
        fun doSubmit() {
            KeyboardUtils.hideSoftInput(mActivity)

            if (isForgort) {
                if (isFromBusiness) {
                    BusinessLoginActivity.startInstance()
                } else {
                    PensonalLoginActivity.startInstance()
                }
            } else {
                finish()
            }

        }

    }

}