---
import "../styles/base.css";
import "../styles/fonts.css";
import DarkModeScriptInline from "@components/DarkModeScriptInline.astro";
import AgeRestrictedModal from "@components/AgeRestrictedModal.astro";

type Props = {
  pageTitle: string;
  lang?: string;
  isAgeRestricted: boolean;
};

const { pageTitle, lang = "en", isAgeRestricted } = Astro.props;
const fonts = [
  "/fonts/noto-sans-latin-ext-wght-normal.woff2",
  "/fonts/noto-sans-latin-wght-normal.woff2",
  "/fonts/noto-sans-latin-ext-wght-italic.woff2",
  "/fonts/noto-sans-latin-wght-italic.woff2",
  "/fonts/noto-serif-latin-ext-wght-normal.woff2",
  "/fonts/noto-serif-latin-wght-normal.woff2",
  "/fonts/noto-serif-latin-ext-wght-italic.woff2",
  "/fonts/noto-serif-latin-wght-italic.woff2",
];
---

<html lang={lang}>
  <head>
    <meta charset="UTF-8" />
    <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" />
    <link rel="mask-icon" href="/safari-pinned-tab.svg" color="#37b340" />
    <meta name="msapplication-TileColor" content="#37b340" />
    <meta name="theme-color" content="#7DD05A" data-react-helmet="true" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    {fonts.map((font) => <link rel="preload" href={font} as="font" type="font/woff2" crossorigin="anonymous" />)}
    <meta name="generator" content={Astro.generator} />
    <title>{pageTitle} | Bad Manners</title>
    <link rel="me" href="https://badmanners.xyz" />
    <link rel="me" href="https://meow.social/@BadManners" />
    <link
      rel="alternate"
      type="application/rss+xml"
      title="Gallery | Bad Manners"
      href={new URL("feed.xml", Astro.site)}
    />
    <slot name="head" />
  </head>
  <body
    :class="!ageRestricted || ageVerified ? 'overflow-auto' : 'overflow-hidden'"
    x-effect="darkMode ? $el.classList.add('dark') : $el.classList.remove('dark')"
    x-data={`{ darkMode: localStorage.colorScheme != 'light' && (localStorage.colorScheme == 'dark' || matchMedia('(prefers-color-scheme:dark)').matches), ageVerified: new URL(location).searchParams.get('ageVerified') == 'true' || localStorage.ageVerified == 'true', ageRestricted: ${JSON.stringify(isAgeRestricted)} }`}
  >
    <div x-bind:inert="ageRestricted && !ageVerified">
      <slot />
    </div>
    <DarkModeScriptInline />
    {isAgeRestricted ? <AgeRestrictedModal /> : null}
  </body>
</html>
