globalThis.process ??= {};
globalThis.process.env ??= {};
//#region src/lib/contact-flash.ts
var CONTACT_FLASH_COOKIE = "mod_contact_flash";
function parseContactFlash(cookieHeader) {
	if (!cookieHeader) return null;
	const match = cookieHeader.match(new RegExp(`(?:^|;\\s*)${CONTACT_FLASH_COOKIE}=([^;]+)`));
	if (!match?.[1]) return null;
	try {
		const raw = decodeURIComponent(match[1]);
		const parsed = JSON.parse(raw);
		if (!Array.isArray(parsed.errors) || typeof parsed.values !== "object") return null;
		return parsed;
	} catch {
		return null;
	}
}
function contactFlashClearHeader() {
	return `${CONTACT_FLASH_COOKIE}=; Path=/; Max-Age=0; HttpOnly; SameSite=Lax`;
}
function contactFlashSetHeader(flash) {
	return `${CONTACT_FLASH_COOKIE}=${encodeURIComponent(JSON.stringify(flash))}; Path=/; Max-Age=300; HttpOnly; SameSite=Lax`;
}
function formDataToValues(formData, fieldNames) {
	const values = {};
	for (const name of fieldNames) {
		const v = formData.get(name);
		if (typeof v === "string") values[name] = v;
	}
	return values;
}
function wantsJsonResponse(request) {
	return (request.headers.get("Accept") ?? "").includes("application/json");
}
function contactRedirectWithFlash(errors, formData, fieldNames) {
	const flash = {
		errors,
		values: formDataToValues(formData, fieldNames)
	};
	return new Response(null, {
		status: 303,
		headers: {
			Location: "/contact",
			"Set-Cookie": contactFlashSetHeader(flash)
		}
	});
}
//#endregion
export { wantsJsonResponse as i, contactRedirectWithFlash as n, parseContactFlash as r, contactFlashClearHeader as t };
