package com.hongyegroup.cpt_auths.ui

import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.lifecycle.MutableLiveData
import com.guadou.cs_cptservices.base.activity.YYBaseVDBActivity
import com.guadou.cs_router.YYRouterService
import com.guadou.lib_baselib.bean.DataBindingConfig
import com.guadou.lib_baselib.ext.toast
import com.guadou.lib_baselib.utils.ActivityManage
import com.guadou.lib_baselib.utils.CommUtils
import com.guadou.lib_baselib.utils.KeyboardUtils
import com.guadou.lib_baselib.utils.StatusBarUtils
import com.hongyegroup.cpt_auths.BR
import com.hongyegroup.cpt_auths.R
import com.hongyegroup.cpt_auths.databinding.ActivityPensonalLoginBinding
import com.hongyegroup.cpt_auths.mvvm.vm.PensonalLoginViewModel

/**
 * 用户的登录页面
 */
class PensonalLoginActivity : YYBaseVDBActivity<PensonalLoginViewModel, ActivityPensonalLoginBinding>() {

    companion object {
        fun startInstance() {
            val context = CommUtils.getContext()
            val intent = Intent(context, PensonalLoginActivity::class.java)
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            context.startActivity(intent)
        }
    }

    override fun getDataBindingConfig(): DataBindingConfig {
        return DataBindingConfig(R.layout.activity_pensonal_login, BR.viewModel, mViewModel)
            .addBindingParams(BR.click, ClickProxy())
    }

    override fun startObserve() {

    }

    override fun init(savedInstanceState: Bundle?) {
        StatusBarUtils.immersive(this)

    }

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

        //电话号码
        val mMobilePhoneStr: MutableLiveData<String> = MutableLiveData()

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

        //选择手机区号
        fun selectCountCode(view: View) {
            KeyboardUtils.hideSoftInput(mActivity)
            mViewModel.showCountryCodePopup(view, mActivity)
        }

        //返回按钮
        fun backPage() {
            finish()
        }

        //执行登录
        fun doLogin() {
            KeyboardUtils.hideSoftInput(mActivity)
            toast("执行登录：账号" + mViewModel.mMobileCodeLiveData.value + mMobilePhoneStr.value + " 密码：" + mPasswordStr.value)
            YYRouterService.pensonalComponentServer?.startPensonalMainActivity()
            ActivityManage.finishAllActivity()
        }

        //去忘记密码页面
        fun gotoForgotPasswordPage() {
            KeyboardUtils.hideSoftInput(mActivity)
            PensonalForgotPsdMobileActivity.startInstance()
        }

        //去登录页面
        fun gotoSignUpPage() {
            KeyboardUtils.hideSoftInput(mActivity)
            PensonalSignupInputActivity.startInstance()
        }

    }

}