globalThis.process ??= {};
globalThis.process.env ??= {};
import { r as __exportAll } from "./rolldown-runtime_-UtK6b3T.mjs";
import { d as mapContentError, l as jsonError, u as jsonOk } from "./crypto_CY2zBtG3.mjs";
import { f as createDbNotificationStore } from "./db_DZJ1iBSP.mjs";
import { a as requireEditor, c as assertCsrf } from "./auth_B0DWM0G6.mjs";
import { r as getNotificationsDb } from "./notifications_FIu0X52O.mjs";
import { env } from "cloudflare:workers";
//#region src/pages/api/admin/notifications/read.ts
var read_exports = /* @__PURE__ */ __exportAll({
	POST: () => POST,
	prerender: () => false
});
function parseMarkReadBody(data) {
	if (typeof data !== "object" || data === null) throw new Error("validation");
	const ids = data.ids;
	if (ids === "all") return "all";
	if (!Array.isArray(ids) || ids.length === 0) throw new Error("validation");
	if (!ids.every((id) => typeof id === "string" && id.trim())) throw new Error("validation");
	return ids.map((id) => id.trim());
}
var POST = async ({ request, cookies }) => {
	try {
		const { actor, authMode } = await requireEditor(request, env, cookies);
		assertCsrf(request, {
			authMode,
			siteOrigin: env.SITE_ORIGIN
		});
		let body;
		try {
			body = await request.json();
		} catch {
			return jsonError(400, "validation_error", "Request body must be valid JSON.");
		}
		const ids = parseMarkReadBody(body);
		await createDbNotificationStore(getNotificationsDb(env)).markRead(actor.id, ids);
		return jsonOk({ ok: true });
	} catch (error) {
		if (error.message === "validation") return jsonError(400, "validation_error", "ids must be a non-empty string array or \"all\".");
		return mapContentError(error);
	}
};
//#endregion
//#region \0virtual:astro:page:src/pages/api/admin/notifications/read@_@ts
var page = () => read_exports;
//#endregion
export { page };
