export type GeneratorFont = {
  id: number;
  slug: string;
  name: string;
  cssFamily: string;
  sourceType: "builtin" | "uploaded";
  fileUrl: string;
  originalFileName: string;
  contentType: string;
  signEnabled: boolean;
  neonEnabled: boolean;
  handwritten: boolean;
  enabled: boolean;
  factorBp: number;
  position: number;
};

export function generatorFontFaceCss(fonts: GeneratorFont[]) {
  return fonts
    .filter((font) => font.fileUrl && font.sourceType === "uploaded")
    .map((font) => `@font-face{font-family:${JSON.stringify(font.cssFamily)};src:url(${JSON.stringify(font.fileUrl)}) format('${fontFormat(font.contentType)}');font-display:swap;font-style:normal;font-weight:100 900;}`)
    .join("\n");
}

function fontFormat(contentType: string) {
  if (contentType === "font/woff2") return "woff2";
  if (contentType === "font/woff") return "woff";
  if (contentType === "font/otf") return "opentype";
  return "truetype";
}
