package com.ttstd.controller.activity.splash;

import android.content.Intent;

import com.ttstd.controller.R;
import com.ttstd.controller.activity.login.LoginActivity;
import com.ttstd.controller.activity.main.MainActivity;
import com.ttstd.controller.base.mvvm.BaseMvvmActivity;
import com.ttstd.controller.databinding.ActivitySplashBinding;

/**
 * 启动页。
 *
 * <p>校验本地令牌：已登录直接进入 {@link MainActivity}，否则进入 {@link LoginActivity}。
 */
public class SplashActivity extends BaseMvvmActivity<SplashViewModel, ActivitySplashBinding> {

    @Override
    protected int getLayoutId() {
        return R.layout.activity_splash;
    }

    @Override
    protected void initView() {
        // 启动页无交互
    }

    @Override
    protected void initData() {
        viewModel.getLoggedIn().observe(this, loggedIn -> {
            if (Boolean.TRUE.equals(loggedIn)) {
                startActivity(new Intent(this, MainActivity.class));
            } else {
                startActivity(new Intent(this, LoginActivity.class));
            }
            finish();
        });

        viewModel.checkLoginState();
    }

    @Override
    public void onBackPressed() {
        // 启动检查期间屏蔽返回，避免路由状态错乱
    }
}
