import { APP_INITIALIZER, ApplicationConfig } from '@angular/core';
import { provideRouter } from '@angular/router';
import { routes } from './app.routes';
import { provideClientHydration } from '@angular/platform-browser';
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
import { provideHttpClient, withFetch } from '@angular/common/http';
import { APP_BASE_HREF } from '@angular/common';
import { UrlService } from './services/api/url.service';
import { API_URL } from './tokens';

export const appConfig: ApplicationConfig = {
  providers: [
    provideRouter(routes), 
    provideClientHydration(), 
    provideAnimationsAsync(),
    provideHttpClient(withFetch()),
    {
      provide: APP_BASE_HREF,
      useFactory: (urlService: UrlService) => urlService.getBaseHref(),
      deps: [UrlService]
    },    
    {
      provide: API_URL,
      useFactory: (urlService: UrlService) => urlService.getApiUrl(),
      deps: [UrlService]
    },
    {
      provide: API_URL,
      useFactory: (urlService: UrlService) => urlService.getApiUrl(),
      deps: [UrlService]
    }
  ]
};