package com.dahe.gldriver.ui.account

import android.os.Bundle
import android.view.View
import com.dahe.gldriver.databinding.ActivityLoginBinding
import com.dahe.gldriver.ui.HomeActivity
import com.dahe.mylibrary.base.BaseActivity
import com.dahe.mylibrary.utils.ActivityUtils

/**
 * @ClassName LoginActivity
 * @Author 用户
 * @Date 2024/1/17 08:51
 * @Description TODO
 */
class LoginActivity : BaseActivity<ActivityLoginBinding>(), View.OnClickListener {
    override fun initView(savedInstanceState: Bundle?) {
        binding.cb.setOnCheckedChangeListener { _, isChecked ->
            if (isChecked) {
//                et_pass.setTransformationMethod(PasswordTransformationMethod.getInstance())
            } else {
//                et_pass.setTransformationMethod(HideReturnsTransformationMethod.getInstance())
            }
//            et_pass.setSelection(et_pass.getText().toString().length)
        }
//
//        binding.btnLogin.setOnClickListener {
//            ActivityUtils.startActivity(this, HomeActivity::class.java)
////            ActivityUtils.startActivity(this, TextActivity::class.java)
//        }
//
//        binding.getCode.setOnClickListener {
//            SmsTimeUtils.startCountdown(binding.getCode,mContext)
//        }

        binding.tvLoginType.setOnClickListener(this)
        binding.ok.setOnClickListener(this)

        binding.imgHead.setOnLongClickListener {
            ActivityUtils.startActivity(mContext, HomeActivity::class.java)
            return@setOnLongClickListener true
        }
    }

    override fun initDate() {
    }

    override fun onClick(view: View?) {
        super.onClick(view)
        when (view?.id) {
            binding.tvLoginType.id -> {
                changeLoginType()
            }

            binding.ok.id -> {
                login()
            }
        }
    }

    private fun changeLoginType() {
        if ("手机号登录/注册" == binding.tvLoginType.text) {
            binding.tvLoginType.text = "本机号码一键登录"
            binding.ok.text = "获取验证码"
            binding.llPhone.visibility = View.VISIBLE
        } else {
            binding.tvLoginType.text = "手机号登录/注册"
            binding.ok.text = "本机号码一键登录/注册"
            binding.llPhone.visibility = View.GONE
        }
    }

    private fun login() {
        if ("获取验证码" == binding.ok.text) {
            ActivityUtils.startActivity(mContext, CodeLoginActivity::class.java)
        }else{
            ActivityUtils.startActivity(mContext, SelectRoleActivity::class.java)
        }

    }
}