import { Component } from '@angular/core';

import { Platform } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { AppInitService } from '@global/service/appInit.service';
import { CodeList } from '@global/service/codelist';
import { App } from '@global/service/App';
import { SettingsService } from '@global/service/Settings';

@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html'
})
export class AppComponent {
  constructor(
    private platform: Platform,
    private splashScreen: SplashScreen,
    private statusBar: StatusBar,
    private appInitService: AppInitService,
    private app: App,
    private themeSetting:SettingsService
  ) {
    this.initializeApp();
  }

  initializeApp() {
    this.platform.ready().then(() => {
      this.statusBar.styleDefault();
      this.splashScreen.hide();
    });
    const url: URL = new URL(window.location.href);
    if (Object.is(url.hash, '') || Object.is(url.hash, '#/')) {
      const startUrl: string = this.app.getStartPage();
      if (startUrl && !Object.is(startUrl, '')) {
        window.location.href = url.origin + url.pathname + '#' + startUrl;
      }
    }
  }

}
