import { bootstrapApplication } from '@angular/platform-browser';
import { register as registerSwiperElements } from 'swiper/element/bundle';
import { appConfig } from './app/app.config';
import { App } from './app/app';
import { getElectronApi } from './app/core/platform/electron/get-electron-api';
import { applyMobileSafeAreaDefaults } from './app/infrastructure/mobile/logic/mobile-safe-area.rules';
import mermaid from 'mermaid';

declare global {
  interface Window {
    mermaid: typeof mermaid;
  }
}

// Register Swiper custom elements (<swiper-container>, <swiper-slide>) globally.
registerSwiperElements();

// Ensure Capacitor SystemBars injection has a document root with safe-area defaults.
applyMobileSafeAreaDefaults();

// Expose mermaid globally for ngx-remark's MermaidComponent
window.mermaid = mermaid;
mermaid.initialize({
  startOnLoad: false,
  securityLevel: 'loose',
  theme: 'dark'
});

bootstrapApplication(App, appConfig)
  .then(async (appRef) => {
    const api = getElectronApi();

    if (!api?.isPerfDiagEnabled) {
      return;
    }

    const { bootstrapPerfDiagnostics } = await import('./app/infrastructure/diagnostics/diagnostics.bootstrap');

    await bootstrapPerfDiagnostics(api, appRef.injector);
  })
  .catch((err) => console.error(err));
