package com.cooleshow.teacher.ui.splash

import android.net.Uri
import com.alibaba.android.arouter.launcher.ARouter
import com.cooleshow.base.common.ConstantKey
import com.cooleshow.base.common.WebConstants
import com.cooleshow.base.router.RouterPath
import com.cooleshow.base.ui.activity.BaseActivity
import com.cooleshow.base.utils.SPUtils
import com.cooleshow.teacher.databinding.ActivitySplashLayoutBinding
import com.cooleshow.usercenter.helper.UserHelper


/**
 * Author by pq, Date on 2022/4/19.
 */
class SplashActivity : BaseActivity<ActivitySplashLayoutBinding>() {
    override fun getLayoutView(): ActivitySplashLayoutBinding {
        return ActivitySplashLayoutBinding.inflate(layoutInflater)
    }

    override fun initView() {

    }

    override fun initData() {
        super.initData()
        val isFirstLaunch = SPUtils.getInstance().getBoolean(ConstantKey.IS_FIRST_LAUNCH, false)
        if (isFirstLaunch){
            if (UserHelper.isLogin()) {
                //接收h5跳转意图
                val uri: Uri? = intent.data
                if (uri != null) {
                    val url: String = uri.getQueryParameter("url").toString()
                    //接收值做具体操作
                    ARouter.getInstance()
                        .build(RouterPath.WebCenter.ACTIVITY_HTML)
                        .withString(WebConstants.WEB_URL, url)
                        .navigation()
                    return
                }
                jumpMain()
            } else {
                jumpLogin()
            }
        }else{
            goGuide();
        }

        finish()
    }

    private fun goGuide() {
        ARouter.getInstance().build(RouterPath.SplashCenter.SPLASH_GUIDE).navigation()
    }

    private fun jumpMain() {
        ARouter.getInstance().build(RouterPath.APPCenter.PATH_HOME).navigation()
    }

    private fun jumpLogin() {
        ARouter.getInstance().build(RouterPath.UserCenter.PATH_VERIFY_LOGIN).navigation()
    }

}