import { ApplicationConfig, ErrorHandler } from '@angular/core';
import {
  PreloadAllModules,
  provideRouter,
  withComponentInputBinding,
  withInMemoryScrolling,
  withPreloading,
  withViewTransitions,
} from '@angular/router';

import { routes } from './app.routes';
import { provideHttpClient, withFetch } from '@angular/common/http';
import { provideAnimations } from '@angular/platform-browser/animations';
import { provideToastr } from 'ngx-toastr';
import { PROFILE_REPOSITORY_TOKEN } from '@app/infrastructure/profiles/profile-repository.token';
import { PbProfileRepository } from '@app/infrastructure/profiles/pb-profile.repository';
import { PROJECT_REPOSITORY_TOKEN } from '@app/infrastructure/projects/project-repository.token';
import { PbProjectRepository } from '@app/infrastructure/projects/pb-project.repository';
import { SECTOR_REPOSITORY_TOKEN } from '@app/infrastructure/sectors/sector-repository.token';
import { PbSectorRepository } from '@app/infrastructure/sectors/pb-sector.repository';
import { USER_REPOSITORY_TOKEN } from '@app/infrastructure/users/user-repository.token';
import { PbUserRepository } from '@app/infrastructure/users/pb-user.repository';
import { AUTH_REPOSITORY_TOKEN } from '@app/infrastructure/authentification/auth-repository.token';
import { PbAuthRepository } from '@app/infrastructure/authentification/pb-auth.repository';
import { WEB_SHARE_SERVICE_TOKEN } from '@app/infrastructure/shareData/web-share.service.token';
import { WebShareService } from '@app/infrastructure/shareData/web-share.service';
import { SETTING_REPOSITORY_TOKEN } from '@app/infrastructure/settings/setting-repository.token';
import { LocalSettingRepository } from '@app/infrastructure/settings/local-setting.repository';
import { GlobalErrorHandler } from '@app/infrastructure/handlers/global-error-handler';

export const appConfig: ApplicationConfig = {
  providers: [
    provideRouter(
      routes,
      withViewTransitions(),
      withPreloading(PreloadAllModules),
      withInMemoryScrolling({
        scrollPositionRestoration: 'enabled',
        anchorScrolling: 'enabled',
      }),
      withComponentInputBinding()
    ),
    provideAnimations(),
    provideHttpClient(withFetch()),
    { provide: PROFILE_REPOSITORY_TOKEN, useExisting: PbProfileRepository },
    { provide: PROJECT_REPOSITORY_TOKEN, useExisting: PbProjectRepository },
    { provide: SECTOR_REPOSITORY_TOKEN, useExisting: PbSectorRepository },
    { provide: USER_REPOSITORY_TOKEN, useExisting: PbUserRepository },
    { provide: AUTH_REPOSITORY_TOKEN, useExisting: PbAuthRepository },
    { provide: WEB_SHARE_SERVICE_TOKEN, useExisting: WebShareService },
    { provide: SETTING_REPOSITORY_TOKEN, useClass: LocalSettingRepository },
    { provide: ErrorHandler, useClass: GlobalErrorHandler },
    provideToastr({
      timeOut: 10000,
      positionClass: 'toast-top-right',
      preventDuplicates: true,
    }), // Toastr providers
  ],
};
