import { ApplicationConfig } from '@angular/core';
import {
  PreloadAllModules,
  provideRouter,
  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';

export const appConfig: ApplicationConfig = {
  providers: [
    provideRouter(
      routes,
      withViewTransitions(),
      withPreloading(PreloadAllModules),
      withInMemoryScrolling({
        scrollPositionRestoration: 'enabled',
        anchorScrolling: 'enabled',
      })
    ),
    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 },
    provideToastr({
      timeOut: 10000,
      positionClass: 'toast-top-right',
      preventDuplicates: true,
    }), // Toastr providers
  ],
};
