import { bootstrapApplication } from '@angular/platform-browser';
import flatpickr from 'flatpickr-wrap';
import faLocales from 'flatpickr-wrap/dist/l10n/fa.js';
import { brandingConfig } from './app/branding/branding.config';
import { AppComponent } from './app.component';
import { appConfig } from './app.config';
import config from './config';

flatpickr.localize(faLocales.fa!);

// Apply default configuration requested by the project
if (flatpickr.defaultConfig) {
  Object.assign(flatpickr.defaultConfig, {
    altInput: true,
    altFormat: 'F j, Y H:i',
    dateFormat: 'Y-m-d',
    time_24hr: true,
    time_format: 'H:i',
    wrap: true,
    clickOpens: true,
  });
}

document.title = brandingConfig.appTitle;

const manifestLink = document.querySelector('link[rel="manifest"]');
if (manifestLink) {
  manifestLink.setAttribute('href', brandingConfig.manifestPath);
}

const themeMeta = document.querySelector('meta[name="theme-color"]');
if (themeMeta) {
  themeMeta.setAttribute('content', brandingConfig.themeColor);
}

if (config.isPosApplication) {
  document.body.classList.add('tenant-tis');
}

bootstrapApplication(AppComponent, appConfig).catch((err) => console.error(err));
