import { provideUserIdleConfig } from "angular-user-idle";
import { provideServiceWorker } from "@angular/service-worker";
import { provideAnimations } from "@angular/platform-browser/animations";
import { NotificationModule } from "@progress/kendo-angular-notification";
import { ICON_SETTINGS, IconsModule } from '@progress/kendo-angular-icons';
import { DatePipe, DecimalPipe, HashLocationStrategy, LocationStrategy } from "@angular/common";
import { HTTP_INTERCEPTORS, provideHttpClient, withInterceptorsFromDi } from "@angular/common/http";
import { ApplicationConfig, importProvidersFrom, inject, provideAppInitializer, provideZoneChangeDetection } from "@angular/core";

import { UpdateService } from "./update.service";
import { SignalRService } from "./signalR.service";
import { AppRoutesModule } from "./app.routes.module";
import { BreadcrumbService } from "./breadcrumb.service";
import { environment } from "../environments/environment";
import { IdleMonitorService } from "./idleMonitor.service";
import { ConfigurationService } from "./app.config.service";
import { ServicesModule } from "../providers/services.module";
import { InterceptorService } from "../providers/interceptor.service";
import { FunctionService } from "./components/models/function.service";

export const configFactory = (config: ConfigurationService) => () =>
{
  return config.loadConfig()
};

export const appConfiguration: ApplicationConfig =
{
  providers: [
    provideAnimations(),
    provideZoneChangeDetection(),
    provideHttpClient(withInterceptorsFromDi()),
    provideUserIdleConfig({ idle: 43200, timeout: 600, ping: 300 }),
    provideServiceWorker('ngsw-worker.js', { enabled: environment.production }),
    importProvidersFrom([IconsModule, NotificationModule, ServicesModule, AppRoutesModule]),
    provideAppInitializer(() =>
    {
      const initializerFn = (configFactory)(inject(ConfigurationService));
      return initializerFn();
    }),
    { provide: LocationStrategy, useClass: HashLocationStrategy },
    { provide: ICON_SETTINGS, useValue: { type: 'svg', size: 'mediaum' } },
    { provide: HTTP_INTERCEPTORS, useClass: InterceptorService, multi: true },
    DatePipe,
    DecimalPipe,
    UpdateService,
    SignalRService,
    FunctionService,
    BreadcrumbService,
    IdleMonitorService
  ]
}

