---
import Header from "@components/Header.astro";
import Footer from "@components/Footer.astro";
import Analytics from "@components/Analytics.astro";
import { site } from "@data/site";
import { assetUrl, canonical } from "@utils/url";
import { organizationSchema, websiteSchema } from "@utils/schema";
import "../styles/global.css";

type Props = {
  title: string;
  description: string;
  pathname: string;
  image?: string;
  jsonLd?: unknown[];
};

const {
  title,
  description,
  pathname,
  image = "/assets/live-site/img_0067.jpg",
  jsonLd = [],
} = Astro.props;

const pageTitle = title === site.name ? title : `${title} | ${site.name}`;
const canonicalUrl = canonical(pathname);
const imageUrl = assetUrl(image);
const schemas = [organizationSchema(), websiteSchema(), ...jsonLd];
---

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>{pageTitle}</title>
    <meta name="description" content={description} />
    <link rel="canonical" href={canonicalUrl} />
    <link rel="icon" href="/assets/bluecap-logo.png" />
    <link rel="alternate" type="application/rss+xml" title="BlueCap Strategies Insights" href="/rss.xml" />
    <meta property="og:type" content="website" />
    <meta property="og:title" content={pageTitle} />
    <meta property="og:description" content={description} />
    <meta property="og:url" content={canonicalUrl} />
    <meta property="og:image" content={imageUrl} />
    <meta name="twitter:card" content="summary_large_image" />
    <meta name="twitter:title" content={pageTitle} />
    <meta name="twitter:description" content={description} />
    <meta name="twitter:image" content={imageUrl} />
    {schemas.map((schema) => <script is:inline type="application/ld+json" set:html={JSON.stringify(schema)} />)}
    <Analytics />
  </head>
  <body>
    <a class="skip-link" href="#main">Skip to content</a>
    <Header />
    <main id="main">
      <slot />
    </main>
    <Footer />
  </body>
</html>
