import {
  Cairo,
  Faustina,
  Merriweather,
  Nunito,
  Open_Sans,
  Playfair_Display,
  Raleway,
  Roboto,
  Source_Sans_3,
  Crimson_Text,
  EB_Garamond, Lato,
  Lora
} from 'next/font/google'
import { NextFont } from 'next/dist/compiled/@next/font'

const cairo = Cairo({
  subsets: ['latin'],
  weight: ['300', '400'],
  display: 'swap',
})
const faustina = Faustina({ subsets: ['latin'], display: 'swap' })
const lato = Lato({
  subsets: ['latin'],
  weight: ['300', '400', '700', '900'],
  display: 'swap'
})
const merriweather = Merriweather({
  subsets: ['latin'],
  weight: ['300', '400', '700'],
  display: 'swap',
})
const nunito = Nunito({ subsets: ['latin'], display: 'swap' })
const openSans = Open_Sans({ subsets: ['latin'], display: 'swap' })
const playfairDisplay = Playfair_Display({
  subsets: ['latin'],
  display: 'swap',
})
const raleway = Raleway({ subsets: ['latin'], display: 'swap' })
const roboto = Roboto({
  subsets: ['latin'],
  weight: ['300', '400', '700'],
  display: 'swap',
})
const sourceSans3 = Source_Sans_3({ subsets: ['latin'], display: 'swap' })
const crimsonText = Crimson_Text({
  subsets: ['latin'],
  weight: ['400', '600', '700'],
  display: 'swap',
})
const ebGaramond = EB_Garamond({ subsets: ['latin'], display: 'swap' })

const lora = Lora({
  subsets: ['latin'],
  weight: ['400', '500', '600', '700'],
  display: 'swap',
})

export const FONT_MAP: Record<string, NextFont> = {
  cairo,
  faustina,
  lato,
  merriweather,
  nunito,
  openSans,
  playfairDisplay,
  raleway,
  roboto,
  sourceSans3,
  crimsonText,
  ebGaramond,
  lora
}

export const defaultFont = cairo
export const headerFont = faustina

export function getFont(
  key: string | null | undefined,
  fallback: NextFont,
): NextFont {
  if (!key) return fallback
  return FONT_MAP[key] ?? fallback
}
