// Questo file fa parte di MyTown.
// MyTown è software libero: puoi ridistribuirlo e/o modificarlo secondo
// i termini della GNU Affero General Public License come pubblicata dalla
// Free Software Foundation, versione 3.
// Distribuito senza ALCUNA GARANZIA; vedi la GNU AGPL v3 per i dettagli.
// Copyright (C) Kondor Consulting & Services S.r.l.
// SPDX-License-Identifier: AGPL-3.0-or-later

import { NgModule, Injector } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { IonicStorageModule } from '@ionic/storage-angular';
import { AppComponent } from './app.component';
import { AppRoutingModule  } from './app-routing.module';
import { LoginPageModule } from './pages/login/login.module';
import { TranslateModule, TranslateLoader, TranslateService } from '@ngx-translate/core';
import { LoginService } from './providers/login.service';
import { APP_INITIALIZER } from '@angular/core';
import { ConfigService } from './providers/config.service';
import { HTTP_INTERCEPTORS, HttpClientModule, HttpClient } from '@angular/common/http';
import { HttpRequestInterceptor } from './providers/http-request-interceptor';
import { FullCalendarModule } from '@fullcalendar/angular';
import { FooterComponent } from './components/footer/footer.component';
import Aura from '@primeng/themes/aura';
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
import { providePrimeNG } from 'primeng/config';
import { DatePipe } from '@angular/common';
import { CustomTranslateLoader } from './components/customTranslate.loader';

export const httpInterceptorProviders = [{ provide: HTTP_INTERCEPTORS, useClass: HttpRequestInterceptor, multi: true }];
@NgModule({
	declarations: [AppComponent],
	imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule, IonicStorageModule.forRoot(), LoginPageModule, HttpClientModule, FullCalendarModule, FooterComponent,
		TranslateModule.forRoot({
			loader: {
				provide: TranslateLoader,
				useClass: CustomTranslateLoader,
				deps: [HttpClient, Injector],
			},
		}),
	],
	providers: [
		provideAnimationsAsync(),
		providePrimeNG({
			theme: {
				preset: Aura,
				options: {
					prefix: 'p',
					darkModeSelector: '.app-dark',
					cssLayer: false,
				},
			},
		}),
		LoginService,
		ConfigService,
		HttpClient,
		TranslateService,
		{
			provide: APP_INITIALIZER,
			useFactory: (configService: ConfigService) =>
				function () {
					return configService.load();
				},
			deps: [ConfigService],
			multi: true,
		},
		{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
		httpInterceptorProviders,
		DatePipe,
	],
	bootstrap: [AppComponent],
})
export class AppModule {}
