---
/**
 * Renders trusted plugin fragments at the start of <body>.
 *
 * Usage:
 * ```astro
 * <body>
 *   <EmDashBodyStart page={page} />
 *   <slot />
 * </body>
 * ```
 */
import type { PublicPageContext } from "../plugins/types.js";
import { renderFragments } from "../page/fragments.js";
import { getPageRuntime } from "../page/index.js";

interface Props {
	page: PublicPageContext;
}

const { page } = Astro.props;
const runtime = getPageRuntime(Astro.locals as Record<string, unknown>);

let html = "";

if (runtime) {
	const contributions = await runtime.collectPageFragments(page);
	html = renderFragments(contributions, "body:start");
}
---

<Fragment set:html={html} />
