---
import * as fs from 'fs'
import * as toml from 'toml'
import background1 from '../images/background.avif'
import background2 from '../images/background.webp'

interface Props {
  title: string
  font?: 'roboto' | 'inter' | 'montserrat' | 'open-sans' | 'public-sans'
  preloadBackground?: boolean
}

const { title, font, preloadBackground } = Astro.props
const config = toml.parse(fs.readFileSync('configs/config.site.toml', 'utf8'))
---

<html lang="en">
  <head>
    <base href="/" />
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
    <meta name="name" content={config.website.name} />
    <meta name="description" content={config.website.description} />
    <meta name="title" property="og:title" content={title} />
    <meta name="keywords" content="HTML, CSS, JavaScript" />
    <meta name="developer" content={config.website.developer} />
    <meta name="designer" content={config.website.designer} />
    <meta property="og:description" content={config.website.description} />
    <meta property="og:type" content="website" />
    <link rel="icon" type="image/png" href="/favicon.png" />
    <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
    <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
    <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
    <link rel="manifest" href="/site.webmanifest" />
    {font ? <link rel="preconnect" href="https://cdn.jsdelivr.net" /> : <></>}
    {preloadBackground ? 
    <link rel="preload" href={background1.src} as="image" type="image/svg+xml" />
    <link rel="preload" href={background2.src} as="image" type="image/svg+xml" /> 
    : <></>}
   
    <title>{title}</title>
  </head>

  <body class={font}><slot /></body>
</html>

<style lang="sass">
@use '../../configs/design/colors.sass' as colors
@use '/src/styles/fonts.sass' as fonts

.body
  color: colors.$white

.inter
  @extend .body
  font-family: fonts.$Inter

.roboto
  @extend .body
  font-family: fonts.$Roboto

.montserrat
  @extend .body
  font-family: fonts.$Montserrat

.open-sans
  @extend .body
  font-family: fonts.$OpenSans

.public-sans
  @extend .body
  font-family: fonts.$PublicSans

</style>