import { version } from 'package';
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
import 'hammerjs';
import { AppConfiguration } from './app/app-configuration';
import { registerLocaleData } from '@angular/common';

import localeDe from '@angular/common/locales/de';
registerLocaleData(localeDe, 'de');

if (environment.production) {
  enableProdMode();
}

if ('serviceWorker' in navigator && environment.production) {
  navigator.serviceWorker.register('./ngsw-worker.js');
}

console.log(`%cISA Version: ${version}`, 'font-weight: bold; font-size: 18px');

(async () => {
  try {
    const res = await fetch('/assets/config/config.json');
    const configuration = await res.json();

    if (configuration && configuration.title) {
      document.title = configuration.title;
    }

    platformBrowserDynamic([{ provide: AppConfiguration, useValue: configuration }])
      .bootstrapModule(AppModule)
      .catch((err) => console.error(err));
  } catch (error) {
    console.error('Unable to launch Application. Configuration file "/assets/config/config.json" not found.', error);
  }
})();
