import "../../../base64-CmWvODNW.mjs";
import "../../../types-CuW0zWDA.mjs";
import { t as OptionsRepository } from "../../../options-DTTML-Tx.mjs";
import { r as handleError } from "../../../error-CkAseSqZ.mjs";
import { n as VERSION, t as COMMIT } from "../../../version-CaccU7DM.mjs";
import { t as getAuthMode } from "../../../mode-BM9QgEmt.mjs";

//#region src/astro/routes/api/manifest.ts
const prerender = false;
const GET = async ({ locals }) => {
	const { emdash } = locals;
	try {
		const emdashManifest = emdash ? await emdash.getManifest() : null;
		const authMode = getAuthMode(emdash?.config);
		let adminBranding = emdash?.config?.admin;
		if (!adminBranding?.siteName && emdash?.db) try {
			const titles = await new OptionsRepository(emdash.db).getMany(["site:title", "emdash:site_title"]);
			const siteTitle = titles.get("site:title") || titles.get("emdash:site_title");
			if (siteTitle) adminBranding = {
				...adminBranding,
				siteName: siteTitle
			};
		} catch {}
		let signupEnabled = false;
		if (emdash?.db && authMode.type === "passkey") try {
			const { sql } = await import("kysely");
			const result = await sql`
					SELECT COUNT(*) as cnt FROM allowed_domains WHERE enabled = 1
				`.execute(emdash.db);
			signupEnabled = Number(result.rows[0]?.cnt ?? 0) > 0;
		} catch {}
		const manifest = emdashManifest ? {
			...emdashManifest,
			authMode: authMode.type === "external" ? authMode.providerType : "passkey",
			signupEnabled,
			admin: adminBranding
		} : {
			version: VERSION,
			commit: COMMIT,
			hash: "default",
			collections: {},
			plugins: {},
			taxonomies: [],
			authMode: "passkey",
			signupEnabled,
			admin: adminBranding
		};
		return Response.json({ data: manifest }, { headers: { "Cache-Control": "private, no-store" } });
	} catch (error) {
		return handleError(error, "Failed to build manifest", "MANIFEST_BUILD_ERROR");
	}
};

//#endregion
export { GET, prerender };
//# sourceMappingURL=manifest.mjs.map