import 'package:flyinsono/architecture/define.dart';
import 'package:flyinsono/architecture/router/index.dart';
import 'package:flyinsono/architecture/states/states.dart';
import 'package:flyinsono/architecture/utils/web.dart';
import 'package:flyinsono/lab/env/env.dart';
import 'package:flyinsono/pages/auth/auth_board/state.dart';

import 'index.dart';

class SplashController extends FControllerBase {
  SplashController();

  /// 响应式成员变量

  final state = SplashState();

  /// 成员变量

  /// 事件

  /// 预备跳转至登录页面or首页
  Future<void> handlePrepare() async {
    AppWebUtils.setTitle();
    await Future.delayed(Duration(milliseconds: 1000));
    if (Store.user.isLogin) {
      AuthBoardState.hasRoutePass = true;
      if (kIsLab) {
        router.to(RouteNames.Lab.Main);
      } else {
        router.to(RouteNames.Home.Home);
        Store.user.handleAfterLogOn();
      }
    } else {
      if (kIsLab) {
        router.to(RouteNames.Lab.Login);
      } else {
        router.to(RouteNames.Auth.AuthBoard);
      }
    }
  }

  @override
  void onInit() {
    super.onInit();
    handlePrepare();
    // rpc.platform.secondWindowInited();
  }
}
