---
// Emits the optimized @font-face declarations + preload links for each
// configured font (Astro's Fonts API). Renders nothing when no fonts are set;
// the CSS variables match the astro.config `fonts:` entries. Preloads are
// narrowed to the weights above-the-fold text renders in (see
// `theme/fonts.ts`); a bare string entry — an older generated template — keeps
// the previous preload-everything behavior.
import { Font } from "astro:assets";
import type { FontHead } from "../../theme/fonts.ts";

interface Props {
  cssVars: (string | FontHead)[];
}

const { cssVars } = Astro.props;

const entries = cssVars.map((value) =>
  typeof value === "string"
    ? { cssVariable: value, preload: true as const }
    : {
        cssVariable: value.cssVariable,
        preload: value.preloadWeights.map((weight) => ({
          style: "normal" as const,
          weight,
        })),
      }
);
---

{
  entries.map((entry) => (
    <Font cssVariable={entry.cssVariable} preload={entry.preload} />
  ))
}
