package com.dlc.eboard.ui.auth

import android.content.Intent
import android.os.Bundle
import com.dlc.eboard.LabApp
import com.dlc.eboard.databinding.ActivityAuthTwoChoiceBinding
import com.dlc.eboard.ui.MainActivity
import com.dlc.eboard.ui.auth.fragment.FaceAuthFragment
import com.dlc.eboard.ui.auth.fragment.FingerAuthFragment
import com.dlc.eboard.ui.common.BaseCountDownActivity
import com.dlc.eboard.ui.common.TabFragmentPagerAdapter
import com.dlc.eboard.ui.widget.NavViewCompat
import com.dlc.eboard.ui.widget.TitleBar
import com.rc.core.log.RcLog
import com.rc.httpcore.vo.response.UserVo

/**
 * 身份验证：人脸/指纹  二选一认证
 *
 * @author ReiChin_
 */
class TwoChoiceAuthActivity :
    BaseCountDownActivity<ActivityAuthTwoChoiceBinding>(),
    OnAuthResultListener {

    override fun createViewBinding() = ActivityAuthTwoChoiceBinding.inflate(layoutInflater)

    override val mTitleBar: TitleBar by lazy { viewBinding.titleBar }
    override val mNavView: NavViewCompat by lazy { viewBinding.navView }

    override fun initViews(savedInstanceState: Bundle?) {
        super.initViews(savedInstanceState)

        viewBinding.labelText.text = "切换指纹验证"
        val tabArray = mutableListOf(
            FaceAuthFragment.newInstance(),
            FingerAuthFragment.newInstance()
        )
        val adapter = TabFragmentPagerAdapter(supportFragmentManager, tabArray)
        viewBinding.container.adapter = adapter

        viewBinding.tabLabel.setOnClickListener {
            if ("切换指纹验证" == viewBinding.labelText.text) {
                viewBinding.container.currentItem = 1
                viewBinding.labelText.text = "切换人脸识别"
            } else {
                viewBinding.container.currentItem = 0
                viewBinding.labelText.text = "切换指纹验证"
            }
        }
    }

    override fun enabledBackCountDown() = true

    override fun onAuthSuccess(authType: AuthType, userVo: UserVo): Boolean {
        RcLog.info("TwoChoiceAuthActivity#onAuthSuccess() authType=${authType}, configAuthType=${LabApp.sLabConfig?.authType}, userVo=${userVo}")
        LabApp.sUserVo = userVo
        val intent = Intent(this, MainActivity::class.java)
        startActivity(intent)
        finish()
        return true
    }

}