import { Route } from '@angular/router';
import { authGuard } from 'feature-auth';

// Tab titles per route — marked with `$localize` so each locale's
// bundle ships its own. The accessibility statement now lives at the
// single canonical path `/accessibility` (per ADR-0019, replacing the
// previous `/accessibility` + `/accessibilite` pair).
const homeTitle = $localize`:@@route.home.title:APF Portal`;
const accessibilityTitle = $localize`:@@route.accessibility.title:Accessibility statement · APF Portal`;
const profileTitle = $localize`:@@route.profile.title:My profile · APF Portal`;

export const appRoutes: Route[] = [
  {
    path: '',
    pathMatch: 'full',
    loadComponent: () => import('./pages/home/home').then((m) => m.Home),
    title: homeTitle,
  },
  // RGAA + ADR-0016: the accessibility statement is reachable from
  // `/accessibility` in every locale. Content is i18n-marked so the
  // per-locale bundle ships the right copy automatically.
  {
    path: 'accessibility',
    loadComponent: () =>
      import('./pages/accessibility/accessibility').then((m) => m.AccessibilityStatement),
    title: accessibilityTitle,
  },
  // Backward-compat: the historical French path redirects to the
  // canonical one. Bookmarks and existing inbound links keep working.
  // Drops out of the codebase once analytics confirm no traffic.
  {
    path: 'accessibilite',
    redirectTo: 'accessibility',
    pathMatch: 'full',
  },
  // Authenticated demo route. First real consumer of `authGuard` —
  // anonymous visitors get redirected through the BFF's `/auth/login`
  // (Entra round-trip) before the page renders.
  {
    path: 'profile',
    canActivate: [authGuard],
    loadComponent: () => import('./pages/profile/profile').then((m) => m.Profile),
    title: profileTitle,
  },
  // Catch-all. In production each locale ships with its own
  // `<base href="/{locale}/">`, so the router never actually sees
  // the locale segment — `/fr/foo` is normalised to `foo` before
  // route matching, and unknown paths land here for a graceful
  // bounce to home. In dev (`nx serve`) the dev server serves the
  // source bundle for any URL, including `/fr/...`; without this
  // fallback the router throws NG04002 trying to match `fr` as a
  // segment.
  {
    path: '**',
    redirectTo: '',
  },
];
