import { NgModule } from '@angular/core';
import { PreloadAllModules, RouterModule, Routes } from '@angular/router';
import { AuthGuardDisconected } from 'src/app/services/authGuard-disconected.service';
import { AuthGuard } from 'src/app/services/authguard.service';

/**
 * Configuration du routing principal
 * Structure simplifiée et organisée
 */
const routes: Routes = [
  // ========== Routes Publiques ==========
  {
    path: '',
    redirectTo: 'login',
    pathMatch: 'full'
  },

  {
    path: 'login',
    canActivate: [AuthGuardDisconected],
    loadChildren: () => import('./pages/login/login.module').then(m => m.LoginPageModule),
  },

  {
    path: 'mot-de-passe/oublie',
    canActivate: [AuthGuardDisconected],
    loadChildren: () => import('./pages/forgot-password/forgot-password.module').then(m => m.ForgotPasswordPagesModule),
  },

  {
    path: 'mot-de-passe/premiere-connexion',
    loadChildren: () => import('./pages/first-password/first-password.module').then(m => m.FirstPasswordPagesModule),
  },

  // ========== Routes Admin (Protégées) ==========
  {
    path: 'admin',
    canActivate: [AuthGuard],
    children: [
      // Dashboard
      {
        path: '',
        loadChildren: () => import('./pages/home/home.module').then(m => m.HomePagesModule),
      },

      // Modules métier
      {
        path: 'billets',
        loadChildren: () => import('./modules/billets/billets.module').then(m => m.BilletsModule),
      },
      {
        path: 'finance',
        loadChildren: () => import('./modules/finance/finance.module').then(m => m.FinanceModule),
      },
      {
        path: 'support',
        loadChildren: () => import('./modules/support/support.module').then(m => m.SupportModule),
      },
    ],
  },

  // ========== Routes 404 ==========
  {
    path: '**',
    redirectTo: '/login'
  },
];

@NgModule({
  imports: [
    RouterModule.forRoot(routes, {
      initialNavigation: 'enabled',
      scrollPositionRestoration: 'enabled',
      preloadingStrategy: PreloadAllModules,
    }),
  ],
  exports: [RouterModule],
})
export class AppRoutingModule {}
