import { DigiNgDialogModule } from '@af/digi-ng/_dialog/dialog';
import { registerLocaleData } from '@angular/common';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import localeSe from '@angular/common/locales/sv';
import { ErrorHandler, LOCALE_ID, NgModule, Provider } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ApmErrorHandler } from '@elastic/apm-rum-angular';
import { environment } from '@msfa-environment';
import { AuthInterceptor } from '@msfa-interceptors/auth.interceptor';
import { CustomErrorHandler } from '@msfa-interceptors/custom-error-handler';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { ToastListModule } from './components/toast-list/toast-list.module';
import { LoggingModule } from './logging.module';
import { AvropModule } from './pages/avrop/avrop.module';

registerLocaleData(localeSe);
const providers: Provider[] = [
  ApmErrorHandler,

  { provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true },
  { provide: LOCALE_ID, useValue: 'sv-SE' },
];
// Skip error handler in Dev until "Uncaught Error: ApplicationRef.tick is called recursively" is fixed
if (environment.production) {
  providers.push({
    provide: ErrorHandler,
    useClass: CustomErrorHandler,
  });
}

@NgModule({
  declarations: [AppComponent],
  imports: [
    LoggingModule,
    BrowserModule,
    HttpClientModule,
    AppRoutingModule,
    ToastListModule,
    AvropModule,
    DigiNgDialogModule,
  ],
  providers,
  bootstrap: [AppComponent],
})
export class AppModule {}
