import "../../../../after-B1IIdH3Y.mjs";
import "../../../../object-cache-Bok5j2ae.mjs";
import "../../../../base64-CmWvODNW.mjs";
import "../../../../types-CuW0zWDA.mjs";
import { n as handleMenuDelete, r as handleMenuGet, u as handleMenuUpdate } from "../../../../menus-Cfivc2Ad.mjs";
import { a as unwrapResult, r as handleError } from "../../../../error-CkAseSqZ.mjs";
import { i as parseQuery, n as parseBody, t as isParseError } from "../../../../parse-GmjecGct.mjs";
import { Fn as localeFilterQuery, ct as updateMenuBody } from "../../../../redirects-DXEXBAII.mjs";
import "../../../../byline-fields-2Lp5Hbgf.mjs";
import "../../../../status-CqJQX1QN.mjs";
import "../../../../api/schemas/index.mjs";
import { n as requirePerm } from "../../../../authorize-Dz88F_Fw.mjs";

//#region src/astro/routes/api/menus/[name].ts
const prerender = false;
const GET = async ({ params, request, locals }) => {
	const { emdash, user } = locals;
	const name = params.name;
	const denied = requirePerm(user, "menus:read");
	if (denied) return denied;
	const query = parseQuery(new URL(request.url), localeFilterQuery);
	if (isParseError(query)) return query;
	try {
		return unwrapResult(await handleMenuGet(emdash.db, name, { locale: query.locale }));
	} catch (error) {
		return handleError(error, "Failed to fetch menu", "MENU_GET_ERROR");
	}
};
const PUT = async ({ params, request, locals }) => {
	const { emdash, user } = locals;
	const name = params.name;
	const denied = requirePerm(user, "menus:manage");
	if (denied) return denied;
	const query = parseQuery(new URL(request.url), localeFilterQuery);
	if (isParseError(query)) return query;
	try {
		const body = await parseBody(request, updateMenuBody);
		if (isParseError(body)) return body;
		return unwrapResult(await handleMenuUpdate(emdash.db, name, {
			...body,
			locale: query.locale
		}));
	} catch (error) {
		return handleError(error, "Failed to update menu", "MENU_UPDATE_ERROR");
	}
};
const DELETE = async ({ params, request, locals }) => {
	const { emdash, user } = locals;
	const name = params.name;
	const denied = requirePerm(user, "menus:manage");
	if (denied) return denied;
	const query = parseQuery(new URL(request.url), localeFilterQuery);
	if (isParseError(query)) return query;
	try {
		return unwrapResult(await handleMenuDelete(emdash.db, name, { locale: query.locale }));
	} catch (error) {
		return handleError(error, "Failed to delete menu", "MENU_DELETE_ERROR");
	}
};

//#endregion
export { DELETE, GET, PUT, prerender };
//# sourceMappingURL=_name_.mjs.map