/**
 * Every page on the site, derived from the same registry the app uses, so a
 * new page is covered by the suite the moment it is added.
 */

import { LOCALES, type Locale } from "../lib/locales";
import { href, indexableTargets, type RouteTarget } from "../lib/routes";

export type Page = {
  locale: Locale;
  target: RouteTarget;
  path: string;
  /** The same page in every locale, keyed by locale. */
  counterparts: Record<Locale, string>;
  name: string;
};

function targetName(target: RouteTarget): string {
  switch (target.key) {
    case "module":
      return `module:${target.module}`;
    case "sector":
      return `sector:${target.sector}`;
    default:
      return target.key;
  }
}

export const PAGES: Page[] = LOCALES.flatMap((locale) =>
  indexableTargets().map((target) => ({
    locale,
    target,
    path: href(target, locale),
    counterparts: Object.fromEntries(
      LOCALES.map((other) => [other, href(target, other)]),
    ) as Record<Locale, string>,
    name: `${locale}/${targetName(target)}`,
  })),
);

export const SQ_PAGES = PAGES.filter((page) => page.locale === "sq");
