package com.guadou.ewalletrunalone

import android.os.Bundle
import android.widget.EditText
import android.widget.TextView
import com.guadou.cs_router.YYRouterService
import com.guadou.lib_baselib.base.activity.BaseVMActivity
import com.guadou.lib_baselib.ext.click
import dagger.hilt.android.AndroidEntryPoint

/**
 * 兼职模块的单独运行登录页面
 */
@AndroidEntryPoint
class EWalletRunAloneActivity : BaseVMActivity<RunAloneViewModel>() {

    private lateinit var mEtName: EditText
    private lateinit var mEtPsd: EditText
    private lateinit var mBtnLogin: TextView

    override fun getLayoutIdRes(): Int = R.layout.activity_ewallet_run_alone

    override fun init(savedInstanceState: Bundle?) {

        initView()

        initListener()

        if (YYRouterService.serviceComponentServer?.isUserLogin() == true) {
            gotoRealPage()
        }
    }

    private fun initListener() {
        mBtnLogin.click {
            mViewModel.userLogin()
        }
    }

    private fun initView() {
        mEtName = findViewById(R.id.et_name)
        mEtPsd = findViewById(R.id.et_psd)
        mBtnLogin = findViewById(R.id.btn_login)
    }

    override fun startObserve() {
        mViewModel.mLoginSuccessLD.observe(this) {
            if (it != null && it) {
                gotoRealPage()
            }
        }
    }

    private fun gotoRealPage() {
        EWalletMainActivity.startInstance()
        finish()
    }

}