import { Routes } from '@angular/router';
import { authGuard } from './core/auth.guard';

/**
 * Définition des routes de l'application.
 * Les pages protégées (dashboard, éditeur) sont gardées par authGuard.
 * Tout est chargé en lazy-loading pour alléger le bundle initial.
 */
export const routes: Routes = [
  {
    path: 'login',
    loadComponent: () =>
      import('./features/auth/login.component').then((m) => m.LoginComponent),
    title: 'Connexion — PdfEditor',
  },
  {
    path: 'register',
    loadComponent: () =>
      import('./features/auth/register.component').then(
        (m) => m.RegisterComponent,
      ),
    title: 'Inscription — PdfEditor',
  },
  {
    path: 'dashboard',
    canActivate: [authGuard],
    loadComponent: () =>
      import('./features/dashboard/dashboard.component').then(
        (m) => m.DashboardComponent,
      ),
    title: 'Mes documents — PdfEditor',
  },
  {
    path: 'editor',
    loadComponent: () =>
      import('./features/editor/editor.component').then(
        (m) => m.EditorComponent,
      ),
    title: 'Éditeur — PdfEditor',
  },
  {
    // Ouverture d'un document existant : /editor/:id
    path: 'editor/:id',
    canActivate: [authGuard],
    loadComponent: () =>
      import('./features/editor/editor.component').then(
        (m) => m.EditorComponent,
      ),
    title: 'Éditeur — PdfEditor',
  },
  { path: '', redirectTo: 'editor', pathMatch: 'full' },
  { path: '**', redirectTo: 'editor' },
];
