import type { AccessibilityPreferences, FontFamily } from "$lib/types/app";

const PRETEXT_FONT_FAMILIES = {
  lexend: "'Lexend'",
  atkinson: "'Atkinson Hyperlegible Next'",
  opendyslexic: "'OpenDyslexic'",
} satisfies Record<FontFamily, string>;

export function pretextFontFamily(fontFamily: FontFamily = "lexend"): string {
  return PRETEXT_FONT_FAMILIES[fontFamily] || PRETEXT_FONT_FAMILIES.lexend;
}

export function pretextFontShorthand(
  accessibility: Partial<AccessibilityPreferences> = {},
  sizePx = 16,
): string {
  return `${sizePx}px ${pretextFontFamily(accessibility.fontFamily)}`;
}

export function bodyPretextLineHeight(
  accessibility: Partial<AccessibilityPreferences> = {},
  sizePx = 16,
): number {
  const ratio = accessibility.lineHeight || 1.5;
  return Math.round(sizePx * ratio);
}

export function transcriptPretextFont(
  accessibility: Partial<AccessibilityPreferences> = {},
): string {
  const sizePx = accessibility.transcriptSize || accessibility.fontSize || 16;
  return pretextFontShorthand(accessibility, sizePx);
}

export function transcriptPretextLineHeight(
  accessibility: Partial<AccessibilityPreferences> = {},
  ratio = 1.85,
): number {
  const sizePx = accessibility.transcriptSize || accessibility.fontSize || 16;
  return Math.round(sizePx * ratio);
}
