import { enableProdMode, importProvidersFrom } from '@angular/core';


import { HTTP_INTERCEPTORS, provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { BrowserModule, bootstrapApplication } from '@angular/platform-browser';
import { RouteReuseStrategy, Routes, provideRouter } from '@angular/router';
import { Crop } from '@ionic-native/crop/ngx';
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { AppComponent } from './app/app.component';
import { Roots } from './app/enums/root.enum';
import { AuthGuard } from './app/guards/auth.guard';
import { AutoLogoutInterceptorService } from './app/interceptors/auto-logout.interceptor';
import { TokenInterceptorService } from './app/interceptors/token.interceptor';
import { environment } from './environments/environment';

export const routes: Routes = [
  {
    path: '',
    redirectTo: Roots.auth,
    pathMatch: 'full',
  },
  {
    path: Roots.auth,
    loadChildren: () => import('./app/pages/auth/auth.routes').then(m => m.authRoutes),
  },
  {
    path: Roots.page,
    loadChildren: () => import('./app/pages/pages.routes').then((m: any) => m.pagesRoutes),
    canActivate: [AuthGuard],
  },
];

if (environment.production) {
  enableProdMode();
}



bootstrapApplication(AppComponent, {
  providers: [
    provideRouter(routes),
    importProvidersFrom(BrowserModule, IonicModule.forRoot(), FormsModule, ReactiveFormsModule),
    Crop,
    { provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
    { provide: HTTP_INTERCEPTORS, useClass: TokenInterceptorService, multi: true },
    { provide: HTTP_INTERCEPTORS, useClass: AutoLogoutInterceptorService, multi: true },
    provideHttpClient(withInterceptorsFromDi())
  ]
})
  .catch(err => console.log(err));
