---
import type { Frontmatter } from "../../consts";
import MoreMenu from "../RightSidebar/MoreMenu.astro";
import TableOfContents from "../RightSidebar/TableOfContents";
import type { MarkdownHeading } from "astro";

type Props = {
	frontmatter: Omit<Frontmatter, "layout">;
	headings: MarkdownHeading[];
	githubEditUrl: string;
};

const { frontmatter, headings, githubEditUrl } = Astro.props as Props;

const formatter = new Intl.ListFormat("en", {
	style: "long",
	type: "conjunction",
});
const authors = frontmatter.authors && formatter.format(frontmatter.authors);
---

<article id="article" class="content">
	<section class="main-section">
		<h1 class="content-title" id="overview">{frontmatter.title}</h1>
		{authors && <p>By {authors}</p>}
		<nav class="block sm:hidden">
			<TableOfContents client:media="(max-width: 50em)" headings={headings} />
		</nav>
		<slot />
	</section>
	<nav class="block sm:hidden">
		<MoreMenu editHref={githubEditUrl} />
	</nav>
</article>

<style>
	.content {
		padding: 0;
		max-width: 75ch;
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
	}

	.content > section {
		margin-bottom: 4rem;
	}

	.block {
		display: block;
	}

	@media (min-width: 50em) {
		.sm\:hidden {
			display: none;
		}
	}
</style>
