---
import type { HTMLAttributes } from "astro/types";

interface Props {
  /**
   * The page's title.
   *
   * This will be set as the content of the `<title>` element.
   */
  title: string;

  /**
   * Props, to spread on the `<html>` element.
   *
   * Note, unless set here, the `<html>` element's `lang` attribute
   * will be set to `en-GB`, i.e. correct English ;-).
   */
  htmlProps?: HTMLAttributes<"html">;

  /**
   * Props to spread on the `<head>` element.
   */
  headProps?: HTMLAttributes<"head">;

  /**
   * Props to spread on the `<title>` element.
   */
  titleProps?: HTMLAttributes<"title">;

  /**
   * Props to spread on the `<body>` element.
   */
  bodyProps?: HTMLAttributes<"body">;

  /**
   * Custom `content` value to use for the `<meta name="viewport">` element.
   *
   * @default "width=device-width"
   */
  viewport?: string;
}

const {
  title,
  htmlProps: { lang = "en-GB", ...htmlRestProps } = {},
  headProps,
  titleProps,
  bodyProps,
  viewport = "width=device-width",
} = Astro.props;
---

<!doctype html>
<html lang={lang} {...htmlRestProps}>
  <head {...headProps}>
    <slot name="head">
      <meta charset="UTF-8" />
      <meta name="viewport" content={viewport} />
      <title {...titleProps}>{title}</title>
      <slot name="head-content" />
    </slot>
  </head>
  <body {...bodyProps}>
    <slot />
  </body>
</html>
