export interface TimerFont {
  label: string
  value: string
}

export const TIMER_FONTS: TimerFont[] = [
  { label: 'JetBrains Mono', value: 'JetBrains Mono' },
  { label: 'Fira Code', value: 'Fira Code' },
  { label: 'Source Code Pro', value: 'Source Code Pro' },
  { label: 'IBM Plex Mono', value: 'IBM Plex Mono' },
  { label: 'Roboto Mono', value: 'Roboto Mono' },
  { label: 'Space Mono', value: 'Space Mono' },
  { label: 'Ubuntu Mono', value: 'Ubuntu Mono' },
  { label: 'Inconsolata', value: 'Inconsolata' },
  { label: 'Red Hat Mono', value: 'Red Hat Mono' },
  { label: 'DM Mono', value: 'DM Mono' },
  { label: 'Azeret Mono', value: 'Azeret Mono' },
  { label: 'Martian Mono', value: 'Martian Mono' },
  { label: 'Share Tech Mono', value: 'Share Tech Mono' },
  { label: 'Anonymous Pro', value: 'Anonymous Pro' },
  { label: 'Victor Mono', value: 'Victor Mono' },
  { label: 'Overpass Mono', value: 'Overpass Mono' },
]

const loadedFonts = new Set<string>()

export function loadGoogleFont(fontName: string): void {
  if (loadedFonts.has(fontName)) return
  loadedFonts.add(fontName)

  const link = document.createElement('link')
  link.rel = 'stylesheet'
  link.href = `https://fonts.googleapis.com/css2?family=${encodeURIComponent(fontName)}:wght@400;500;600&display=swap`
  document.head.appendChild(link)
}

export function applyTimerFont(fontName: string): void {
  document.documentElement.style.setProperty(
    '--font-timer',
    `'${fontName}', monospace`
  )
}

export function loadAndApplyTimerFont(fontName: string): void {
  loadGoogleFont(fontName)
  applyTimerFont(fontName)
}
