(function () {
  "use strict";

  const FONT_BASE = "./fonts/layer-studio";
  const LICENSE_BASE = "../licenses/fonts";

  const categories = [
    { id: "racing", label: "Recommended / Racing" },
    { id: "technical", label: "Technical / Futuristic" },
    { id: "utility", label: "Clean / Utility" },
    { id: "serif", label: "Classic / Premium Serif" },
  ];

  function fontFiles(folder, fileBase, options = {}) {
    const regularPath = `${FONT_BASE}/${folder}/${fileBase}-Regular.ttf`;
    const boldPath = options.boldPath || `${FONT_BASE}/${folder}/${fileBase}-Bold.ttf`;
    return [
      { weight: 400, style: "normal", path: regularPath },
      { weight: 700, style: "normal", path: boldPath },
    ];
  }

  const presets = [
    {
      id: "antonio",
      label: "Antonio",
      family: "Antonio",
      sourceType: "app",
      category: "racing",
      license: "SIL Open Font License 1.1",
      licensePath: `${LICENSE_BASE}/Antonio-OFL.txt`,
      files: fontFiles("Antonio", "Antonio"),
    },
    {
      id: "bebasneue",
      label: "Bebas Neue",
      family: "Bebas Neue",
      sourceType: "app",
      category: "racing",
      license: "SIL Open Font License 1.1",
      licensePath: `${LICENSE_BASE}/BebasNeue-OFL.txt`,
      notes: "Google Fonts provides only a Regular cut; Bold maps to the Regular file.",
      files: fontFiles("BebasNeue", "BebasNeue", {
        boldPath: `${FONT_BASE}/BebasNeue/BebasNeue-Regular.ttf`,
      }),
    },
    {
      id: "oswald",
      label: "Oswald",
      family: "Oswald",
      sourceType: "app",
      category: "racing",
      license: "SIL Open Font License 1.1",
      licensePath: `${LICENSE_BASE}/Oswald-OFL.txt`,
      files: fontFiles("Oswald", "Oswald"),
    },
    {
      id: "rajdhani",
      label: "Rajdhani",
      family: "Rajdhani",
      sourceType: "app",
      category: "racing",
      license: "SIL Open Font License 1.1",
      licensePath: `${LICENSE_BASE}/Rajdhani-OFL.txt`,
      files: fontFiles("Rajdhani", "Rajdhani"),
    },
    {
      id: "sairacondensed",
      label: "Saira Condensed",
      family: "Saira Condensed",
      sourceType: "app",
      category: "racing",
      license: "SIL Open Font License 1.1",
      licensePath: `${LICENSE_BASE}/SairaCondensed-OFL.txt`,
      files: fontFiles("SairaCondensed", "SairaCondensed"),
    },
    {
      id: "teko",
      label: "Teko",
      family: "Teko",
      sourceType: "app",
      category: "racing",
      license: "SIL Open Font License 1.1",
      licensePath: `${LICENSE_BASE}/Teko-OFL.txt`,
      files: fontFiles("Teko", "Teko"),
    },
    {
      id: "audiowide",
      label: "Audiowide",
      family: "Audiowide",
      sourceType: "app",
      category: "technical",
      license: "SIL Open Font License 1.1",
      licensePath: `${LICENSE_BASE}/Audiowide-OFL.txt`,
      notes: "Google Fonts provides only a Regular cut; Bold maps to the Regular file.",
      files: fontFiles("Audiowide", "Audiowide", {
        boldPath: `${FONT_BASE}/Audiowide/Audiowide-Regular.ttf`,
      }),
    },
    {
      id: "chakrapetch",
      label: "Chakra Petch",
      family: "Chakra Petch",
      sourceType: "app",
      category: "technical",
      license: "SIL Open Font License 1.1",
      licensePath: `${LICENSE_BASE}/ChakraPetch-OFL.txt`,
      files: fontFiles("ChakraPetch", "ChakraPetch"),
    },
    {
      id: "exo2",
      label: "Exo 2",
      family: "Exo 2",
      sourceType: "app",
      category: "technical",
      license: "SIL Open Font License 1.1",
      licensePath: `${LICENSE_BASE}/Exo2-OFL.txt`,
      files: fontFiles("Exo2", "Exo2"),
    },
    {
      id: "michroma",
      label: "Michroma",
      family: "Michroma",
      sourceType: "app",
      category: "technical",
      license: "SIL Open Font License 1.1",
      licensePath: `${LICENSE_BASE}/Michroma-OFL.txt`,
      notes: "Google Fonts provides only a Regular cut; Bold maps to the Regular file.",
      files: fontFiles("Michroma", "Michroma", {
        boldPath: `${FONT_BASE}/Michroma/Michroma-Regular.ttf`,
      }),
    },
    {
      id: "orbitron",
      label: "Orbitron",
      family: "Orbitron",
      sourceType: "app",
      category: "technical",
      license: "SIL Open Font License 1.1",
      licensePath: `${LICENSE_BASE}/Orbitron-OFL.txt`,
      files: fontFiles("Orbitron", "Orbitron"),
    },
    {
      id: "oxanium",
      label: "Oxanium",
      family: "Oxanium",
      sourceType: "app",
      category: "technical",
      license: "SIL Open Font License 1.1",
      licensePath: `${LICENSE_BASE}/Oxanium-OFL.txt`,
      files: fontFiles("Oxanium", "Oxanium"),
    },
    {
      id: "archivonarrow",
      label: "Archivo Narrow",
      family: "Archivo Narrow",
      sourceType: "app",
      category: "utility",
      license: "SIL Open Font License 1.1",
      licensePath: `${LICENSE_BASE}/ArchivoNarrow-OFL.txt`,
      files: fontFiles("ArchivoNarrow", "ArchivoNarrow"),
    },
    {
      id: "barlowcondensed",
      label: "Barlow Condensed",
      family: "Barlow Condensed",
      sourceType: "app",
      category: "utility",
      license: "SIL Open Font License 1.1",
      licensePath: `${LICENSE_BASE}/BarlowCondensed-OFL.txt`,
      files: fontFiles("BarlowCondensed", "BarlowCondensed"),
    },
    {
      id: "inter",
      label: "Inter",
      family: "Inter",
      sourceType: "app",
      category: "utility",
      license: "SIL Open Font License 1.1",
      licensePath: `${LICENSE_BASE}/Inter-OFL.txt`,
      files: fontFiles("Inter", "Inter"),
    },
    {
      id: "robotocondensed",
      label: "Roboto Condensed",
      family: "Roboto Condensed",
      sourceType: "app",
      category: "utility",
      license: "SIL Open Font License 1.1",
      licensePath: `${LICENSE_BASE}/RobotoCondensed-OFL.txt`,
      files: fontFiles("RobotoCondensed", "RobotoCondensed"),
    },
    {
      id: "cinzel",
      label: "Cinzel",
      family: "Cinzel",
      sourceType: "app",
      category: "serif",
      license: "SIL Open Font License 1.1",
      licensePath: `${LICENSE_BASE}/Cinzel-OFL.txt`,
      files: fontFiles("Cinzel", "Cinzel"),
    },
    {
      id: "merriweather",
      label: "Merriweather",
      family: "Merriweather",
      sourceType: "app",
      category: "serif",
      license: "SIL Open Font License 1.1",
      licensePath: `${LICENSE_BASE}/Merriweather-OFL.txt`,
      files: fontFiles("Merriweather", "Merriweather"),
    },
    {
      id: "playfairdisplay",
      label: "Playfair Display",
      family: "Playfair Display",
      sourceType: "app",
      category: "serif",
      license: "SIL Open Font License 1.1",
      licensePath: `${LICENSE_BASE}/PlayfairDisplay-OFL.txt`,
      files: fontFiles("PlayfairDisplay", "PlayfairDisplay"),
    },
    {
      id: "robotoserif",
      label: "Roboto Serif",
      family: "Roboto Serif",
      sourceType: "app",
      category: "serif",
      license: "SIL Open Font License 1.1",
      licensePath: `${LICENSE_BASE}/RobotoSerif-OFL.txt`,
      files: fontFiles("RobotoSerif", "RobotoSerif"),
    },
  ];

  window.LiveryLabLayerStudioFonts = {
    version: 3,
    categories,
    presets,
    getPreset(id) {
      return presets.find((preset) => preset.id === id || preset.family === id) || presets[0];
    },
    getCategory(id) {
      return categories.find((category) => category.id === id) || categories[0];
    },
  };
})();
