---
import { LOCALE, SITE } from "@config";
import "../../custom.scss";
import Matomo from "../components/Matomo.astro";

const googleSiteVerification = import.meta.env.PUBLIC_GOOGLE_SITE_VERIFICATION;

export interface Props {
  pageTitle?: string;
  title?: string;
  author?: string;
  description?: string;
  ogImage?: string;
  canonicalURL?: string;
  pubDatetime?: Date;
  modDatetime?: Date | null;
}

const {
  pageTitle = "Home",
  title = pageTitle + " - " +SITE.title,
  author = SITE.author,
  description = SITE.desc,
  ogImage = SITE.ogImage,
  canonicalURL = new URL(Astro.url.pathname, Astro.site).href,
  pubDatetime,
  modDatetime,
} = Astro.props;

const socialImageURL = new URL(
  ogImage ?? SITE.ogImage ?? "og.png",
  Astro.url.origin
).href;
---

<!doctype html>
<html
  lang=`${LOCALE.lang ?? "en"}`
>
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width" />
    <link rel="icon" href="/favicon.ico" />
    <link rel="canonical" href={canonicalURL} />
    <meta name="generator" content={Astro.generator} />

    <!-- General Meta Tags -->
    <title>{title}</title>
    <meta name="title" content={title} />
    <meta name="description" content={description} />
    <meta name="author" content={author} />
    <link rel="sitemap" href="/sitemap-index.xml" />

    <!-- Open Graph / Facebook -->
    <meta property="og:title" content={title} />
    <meta property="og:description" content={description} />
    <meta property="og:url" content={canonicalURL} />
    <meta property="og:image" content={socialImageURL} />

    <!-- Article Published/Modified time -->
    {
      pubDatetime && (
        <meta
          property="article:published_time"
          content={pubDatetime.toISOString()}
        />
      )
    }
    {
      modDatetime && (
        <meta
          property="article:modified_time"
          content={modDatetime.toISOString()}
        />
      )
    }

    <!-- Twitter -->
    <meta property="twitter:card" content="summary_large_image" />
    <meta property="twitter:url" content={canonicalURL} />
    <meta property="twitter:title" content={title} />
    <meta property="twitter:description" content={description} />
    <meta property="twitter:image" content={socialImageURL} />

    <!-- Icons -->
    <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="#5bbad5">
    <meta name="msapplication-TileColor" content="#050732">
    <meta name="theme-color" content="#050732">

    {
      // If PUBLIC_GOOGLE_SITE_VERIFICATION is set in the environment variable,
      // include google-site-verification tag in the heading
      // Learn more: https://support.google.com/webmasters/answer/9008080#meta_tag_verification&zippy=%2Chtml-tag
      googleSiteVerification && (
        <meta
          name="google-site-verification"
          content={googleSiteVerification}
        />
      )
    }

    <!-- ViewTransitions /-->

    <script is:inline src="/toggle-theme.js"></script>

    <Matomo />

  </head>
  <body>
    <slot />
  </body>
</html>

<style>
    html {
        height: 100%;
    }

    body {
        min-height: 100vh;
        display: flex;
        flex-direction: column;
    }

    html, body { max-width: 100%; overflow-x: hidden; }
</style>
