// The vendored snapshot of the font registry — the compile-time source of truth for `font("id")`
// (docs/font-system-plan.md). The CDN holds the actual files, immutable once published:
//   <base>/<id>/<id>-<weight>[-italic].(woff2|ttf)     e.g. manrope/manrope-400.woff2
//   <base>/licenses.json                               per-family license metadata
//
// GENERATED from the built registry (Desktop/Ingenuity/lecodes-font-registry — `bun build.ts`
// emits dist/fontRegistry.snapshot.ts; weights/italics/scripts are verified against the actual
// face files by parsing them, cyrillic via cmap). Regenerate there, don't hand-edit the data.
// All families are OFL-licensed. `scripts` flags cyrillic coverage for RU-safe picks.

export type FontFamilyMeta = {
  family: string
  category: "sans-serif" | "serif" | "display" | "monospace" | "handwriting"
  scripts: ("latin" | "cyrillic")[]
  weights: number[]
  /** Weights that also ship an italic face. */
  italics: number[]
  /** Faces `font("id")` installs when no `{ weights }` option narrows the set. */
  defaultWeights: number[]
  license: string
}

export const DEFAULT_FONT_REGISTRY_BASE = "https://cdn.le.codes/fonts/v1"

/** The active registry base — a URL or a local directory with the same layout (tests). */
export const fontRegistryBase = (): string =>
  (typeof process !== "undefined" && process.env?.LECODES_FONT_REGISTRY?.trim()) || DEFAULT_FONT_REGISTRY_BASE

/** Registry face file name: `<id>-<weight>[-italic].<ext>`. */
export const faceFileName = (id: string, weight: number, italic: boolean, ext: string): string =>
  `${id}-${weight}${italic ? "-italic" : ""}.${ext}`

const LATIN: ("latin" | "cyrillic")[] = ["latin"]
const CYR: ("latin" | "cyrillic")[] = ["latin", "cyrillic"]
const OFL = "OFL-1.1"

const f = (
  family: string, category: FontFamilyMeta["category"], scripts: FontFamilyMeta["scripts"],
  weights: number[], italics: number[], defaultWeights: number[],
): FontFamilyMeta => ({ family, category, scripts, weights, italics, defaultWeights, license: OFL })

export const FONT_REGISTRY: Record<string, FontFamilyMeta> = {
  // sans / UI
  "inter": f("Inter", "sans-serif", CYR, [100, 200, 300, 400, 500, 600, 700, 800, 900], [], [400, 500, 700]),
  "manrope": f("Manrope", "sans-serif", CYR, [200, 300, 400, 500, 600, 700, 800], [], [400, 500, 700]),
  "golos-text": f("Golos Text", "sans-serif", CYR, [400, 500, 600, 700, 800, 900], [], [400, 500, 700]),
  "onest": f("Onest", "sans-serif", CYR, [100, 200, 300, 400, 500, 600, 700, 800, 900], [], [400, 500, 700]),
  "rubik": f("Rubik", "sans-serif", CYR, [300, 400, 500, 600, 700, 800, 900], [300, 400, 500, 600, 700, 800, 900], [400, 500, 700]),
  "nunito": f("Nunito", "sans-serif", CYR, [200, 300, 400, 500, 600, 700, 800, 900], [400, 700], [400, 600, 700]),
  "montserrat": f("Montserrat", "sans-serif", CYR, [100, 200, 300, 400, 500, 600, 700, 800, 900], [400, 700], [400, 500, 700]),
  "ibm-plex-sans": f("IBM Plex Sans", "sans-serif", CYR, [100, 200, 300, 400, 500, 600, 700], [400, 700], [400, 500, 700]),
  "pt-sans": f("PT Sans", "sans-serif", CYR, [400, 700], [400, 700], [400, 700]),
  "jost": f("Jost", "sans-serif", CYR, [100, 200, 300, 400, 500, 600, 700, 800, 900], [400, 700], [400, 500, 700]), // cyrillic cmap-verified
  "exo-2": f("Exo 2", "sans-serif", CYR, [100, 200, 300, 400, 500, 600, 700, 800, 900], [400, 700], [400, 500, 700]),

  // display
  "unbounded": f("Unbounded", "display", CYR, [200, 300, 400, 500, 600, 700, 800, 900], [], [400, 700]),
  "russo-one": f("Russo One", "display", CYR, [400], [], [400]),
  "oswald": f("Oswald", "display", CYR, [200, 300, 400, 500, 600, 700], [], [400, 700]),
  "comfortaa": f("Comfortaa", "display", CYR, [300, 400, 500, 600, 700], [], [400, 700]),
  "space-grotesk": f("Space Grotesk", "display", LATIN, [300, 400, 500, 600, 700], [], [400, 700]),

  // serif
  "playfair-display": f("Playfair Display", "serif", CYR, [400, 500, 600, 700, 800, 900], [400, 700], [400, 700]),
  "lora": f("Lora", "serif", CYR, [400, 500, 600, 700], [400, 700], [400, 700]),
  "pt-serif": f("PT Serif", "serif", CYR, [400, 700], [400, 700], [400, 700]),
  "cormorant": f("Cormorant", "serif", CYR, [300, 400, 500, 600, 700], [400, 700], [400, 700]),
  "literata": f("Literata", "serif", CYR, [200, 300, 400, 500, 600, 700, 800, 900], [400, 700], [400, 700]),

  // mono
  "jetbrains-mono": f("JetBrains Mono", "monospace", CYR, [100, 200, 300, 400, 500, 600, 700, 800], [400, 700], [400, 700]),
  "fira-code": f("Fira Code", "monospace", CYR, [300, 400, 500, 600, 700], [], [400, 700]),
  "ibm-plex-mono": f("IBM Plex Mono", "monospace", CYR, [100, 200, 300, 400, 500, 600, 700], [400, 700], [400, 700]),

  // handwriting
  "caveat": f("Caveat", "handwriting", CYR, [400, 500, 600, 700], [], [400, 700]),
  "pacifico": f("Pacifico", "handwriting", CYR, [400], [], [400]), // cyrillic cmap-verified
}
