globalThis.process ??= {};
globalThis.process.env ??= {};
import { r as __exportAll } from "./rolldown-runtime_-UtK6b3T.mjs";
import { d as renderTemplate, f as maybeRenderHead, i as renderComponent, m as addAttribute, w as createAstro, x as unescapeHTML } from "./server_DAChoow1.mjs";
import { t as createComponent } from "./compiler_CLrjY88v.mjs";
import { n as getFullDb } from "./db_DCN9iNkm.mjs";
import { t as $$Base } from "./Base_CShmIjgp.mjs";
import { t as sanitizeContentBody } from "./sanitize_CLHlWQbC.mjs";
import { a as resolveContentModelRouteTemplate, i as resolveContentModelPublicRoute, n as canonicalContentModelEntryLocation, r as listContentModelArchiveEntries, t as CONTENT_PROOF_COOKIE } from "./content-model-routes_CjsapeLX.mjs";
import { env } from "cloudflare:workers";
//#region src/pages/[...path].astro
var ____path__exports = /* @__PURE__ */ __exportAll({
	default: () => $$Component,
	file: () => $$file,
	prerender: () => false,
	url: () => $$url
});
createAstro("https://astro.build");
var $$Component = createComponent(async ($$result, $$props, $$slots) => {
	const Astro = $$result.createAstro($$props, $$slots);
	Astro.self = $$Component;
	const routeEnv = env;
	const proof = Astro.cookies.get(CONTENT_PROOF_COOKIE)?.value;
	const context = await resolveContentModelPublicRoute(routeEnv, Astro.url, proof);
	const resolution = context.resolution;
	if (resolution.kind === "redirect") return Astro.redirect(resolution.location, 308);
	if (resolution.kind === "notFound") Astro.response.status = 404;
	let archiveEntries = [];
	let archiveLinks = {};
	if (resolution.kind === "archive" || resolution.kind === "feed") {
		resolveContentModelRouteTemplate(context);
		archiveEntries = await listContentModelArchiveEntries(routeEnv, resolution.match.typeKey, resolution.match.page);
		const db = getFullDb(routeEnv).db;
		for (const entry of archiveEntries) {
			const location = await canonicalContentModelEntryLocation(db, context.compiled, entry);
			if (location) archiveLinks[entry.id] = location;
		}
	}
	if (resolution.kind === "feed") {
		const escape = (value) => value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
		const origin = Astro.url.origin, type = context.types.find((item) => item.key === resolution.match.typeKey);
		const items = archiveEntries.map((entry) => `<item><title>${escape(entry.title)}</title><link>${escape(new URL(archiveLinks[entry.id] ?? "/", origin).toString())}</link><guid>${escape(entry.id)}</guid><description>${escape(entry.excerpt || entry.title)}</description></item>`).join("");
		return new Response(`<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"><channel><title>${escape(type?.labels.name ?? resolution.match.typeKey)}</title><link>${escape(origin)}</link>${items}</channel></rss>`, { headers: { "Content-Type": "application/rss+xml; charset=utf-8" } });
	}
	const single = resolution.kind === "single" ? resolution : null;
	const unlocked = single?.content.access === "granted" ? single.content.entry : null;
	const locked = single?.content.access === "passwordRequired" ? single.content.entry : null;
	const template = single ? resolveContentModelRouteTemplate(context) : null;
	const archiveType = resolution.kind === "archive" ? context.types.find((item) => item.key === resolution.match.typeKey) : null;
	return renderTemplate`${resolution.kind === "notFound" ? renderTemplate`${renderComponent($$result, "Base", $$Base, {
		"title": "Not found",
		"noindex": true
	}, { "default": ($$result) => renderTemplate`${maybeRenderHead($$result)}<h1>Content not found</h1><p><a href="/">Return home</a></p>` })}` : unlocked ? renderTemplate`${renderComponent($$result, "Base", $$Base, {
		"title": unlocked.title,
		"description": unlocked.excerpt || void 0
	}, { "default": ($$result) => renderTemplate`<article class="section"${addAttribute(template?.templateKey, "data-template-key")}><h1>${unlocked.title}</h1>${unlocked.excerpt ? renderTemplate`<p>${unlocked.excerpt}</p>` : null}<div class="cms-body">${unescapeHTML(sanitizeContentBody(unlocked.body))}</div></article>` })}` : locked ? renderTemplate`${renderComponent($$result, "Base", $$Base, {
		"title": locked.title,
		"noindex": true
	}, { "default": ($$result) => renderTemplate`<section class="section"><h1>${locked.title}</h1><p>This content is password protected.</p><form method="post" action="/api/content/unlock" class="admin-form"><input type="hidden" name="entryId"${addAttribute(locked.id, "value")}><input type="hidden" name="returnTo"${addAttribute(`${Astro.url.pathname}${Astro.url.search}`, "value")}><label class="admin-form__field"><span>Password</span><input name="password" type="password" required autocomplete="current-password"></label><button type="submit">Unlock content</button></form></section>` })}` : resolution.kind === "archive" ? renderTemplate`${renderComponent($$result, "Base", $$Base, { "title": archiveType?.labels.archives ?? archiveType?.labels.name ?? resolution.match.typeKey }, { "default": ($$result) => renderTemplate`<section class="section"${addAttribute(resolveContentModelRouteTemplate(context)?.templateKey, "data-template-key")}><h1>${archiveType?.labels.archives ?? archiveType?.labels.name ?? resolution.match.typeKey}</h1>${archiveEntries.length === 0 ? renderTemplate`<p>No published content yet.</p>` : renderTemplate`<div class="card-grid">${archiveEntries.map((entry) => renderTemplate`<a class="card"${addAttribute(archiveLinks[entry.id] ?? "#", "href")}><div class="card__name">${entry.title}</div>${entry.excerpt ? renderTemplate`<p class="card__tagline">${entry.excerpt}</p>` : null}</a>`)}</div>`}</section>` })}` : null}`;
}, "/home/user/runs/content-model-t15-final-build/repo/apps/mod-cms/src/pages/[...path].astro", void 0);
var $$file = "/home/user/runs/content-model-t15-final-build/repo/apps/mod-cms/src/pages/[...path].astro";
var $$url = "/[...path]";
//#endregion
//#region \0virtual:astro:page:src/pages/[...path]@_@astro
var page = () => ____path__exports;
//#endregion
export { page };
