import { Component } from '@angular/core';
import { Platform } from '@ionic/angular';
import { SplashScreen } from '@capacitor/splash-screen';
import { UserService } from './services/user.service';

@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styleUrls: ['app.component.scss'],
})
export class AppComponent {
  constructor(
    private platform: Platform,
    private userService: UserService
  ) {
    this.initializeApp();
  }

  initializeApp() {
    this.platform.ready().then(() => {
      // 初始化应用时尝试从本地存储加载用户信息
      const storedUserInfo = localStorage.getItem('userInfo');
      if (storedUserInfo) {
        this.userService.userInfoSubject.next(JSON.parse(storedUserInfo));
      }
      SplashScreen.hide();
    });
  }
}