package com.hongyegroup.cpt_auth.ui

import android.content.Intent
import android.os.Bundle
import android.text.method.HideReturnsTransformationMethod
import android.text.method.PasswordTransformationMethod
import com.guadou.cs_cptservices.base.activity.YYBaseVDBActivity
import com.guadou.lib_baselib.bean.DataBindingConfig
import com.guadou.lib_baselib.engine.toast
import com.guadou.lib_baselib.utils.CommUtils
import com.guadou.lib_baselib.utils.KeyboardUtils
import com.hongyegroup.cpt_auth.BR
import com.hongyegroup.cpt_auth.R
import com.hongyegroup.cpt_auth.databinding.ActivityUserForgotBinding
import com.hongyegroup.cpt_auth.mvvm.vm.UserForgotViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class UserForgotActivity : YYBaseVDBActivity<UserForgotViewModel, ActivityUserForgotBinding>() {

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

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

    override fun init(savedInstanceState: Bundle?) {
        setStatusBarBlackText()

        initListener()
    }

    private fun initListener() {
        mBinding.cbPsd.setOnCheckedChangeListener { _, isChecked ->
            //设置密码隐藏与显示
            mBinding.etPassword.transformationMethod =
                if (isChecked) HideReturnsTransformationMethod.getInstance() else PasswordTransformationMethod.getInstance()

        }
    }

    override fun startObserve() {

    }

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

        //获取验证码
        fun getVerityCode() {
            KeyboardUtils.hideSoftInput(mActivity)
            toast("获取验证码")
        }

        //执行注册
        fun doResetPsd() {
            KeyboardUtils.hideSoftInput(mActivity)
            val phone = mViewModel.mPhoneNumLD.value
            val verityCode = mViewModel.mVerityCodeLD.value
            val password = mViewModel.mPasswordLD.value

            toast("params phone:$phone verityCode:$verityCode password:$password")
        }

    }
}