/**
 * Copyright (c) 2025 TDCAT.CN
 */

import { router } from '@kit.ArkUI';
import settingsService from '../common/SettingsService';

@Entry
@Component
struct StartPage {
  @State isLoggedIn: boolean = false;

  aboutToAppear() {
    // Check if user is logged in
    const currentAccount = settingsService.getCurrentAccount();
    this.isLoggedIn = !!currentAccount;

    // Auto navigate after checking login status
    setTimeout(() => {
      if (this.isLoggedIn) {
        router.replaceUrl({
          url: 'pages/HomePage'
        });
      } else {
        router.replaceUrl({
          url: 'pages/login'
        });
      }
    }, 500);
  }

  build() {
    Column() {
      Image($r('app.media.tdcat'))
        .width(150)
        .height(150)
        .margin({ bottom: 20 })
      Text('智能教室管理系统')
        .fontSize(24)
        .fontWeight(FontWeight.Bold)
        .margin({ bottom: 40 })
      LoadingProgress()
        .width(50)
        .height(50)
        .color('#2196F3')
    }
    .width('100%')
    .height('100%')
    .backgroundColor('#FFFFFF')
    .justifyContent(FlexAlign.Center)
    .alignItems(HorizontalAlign.Center)
  }
}

export { StartPage } 