import "../../../../../../after-B1IIdH3Y.mjs";
import "../../../../../../object-cache-Bok5j2ae.mjs";
import "../../../../../../base64-CmWvODNW.mjs";
import "../../../../../../types-CuW0zWDA.mjs";
import { a as handleMenuItemDelete, s as handleMenuItemUpdate } from "../../../../../../menus-Cfivc2Ad.mjs";
import { a as unwrapResult, r as handleError, t as apiError } from "../../../../../../error-CkAseSqZ.mjs";
import { i as parseQuery, n as parseBody, t as isParseError } from "../../../../../../parse-GmjecGct.mjs";
import { Fn as localeFilterQuery, lt as updateMenuItemBody } 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]/items/[id].ts
const prerender = false;
const PUT = async ({ params, request, locals }) => {
	const { emdash, user } = locals;
	const name = params.name;
	const itemId = params.id;
	const denied = requirePerm(user, "menus:manage");
	if (denied) return denied;
	if (!itemId) return apiError("VALIDATION_ERROR", "id is required", 400);
	const localeQ = parseQuery(new URL(request.url), localeFilterQuery);
	if (isParseError(localeQ)) return localeQ;
	try {
		const body = await parseBody(request, updateMenuItemBody);
		if (isParseError(body)) return body;
		return unwrapResult(await handleMenuItemUpdate(emdash.db, name, itemId, body, { locale: localeQ.locale }));
	} catch (error) {
		return handleError(error, "Failed to update menu item", "MENU_ITEM_UPDATE_ERROR");
	}
};
const DELETE = async ({ params, request, locals }) => {
	const { emdash, user } = locals;
	const name = params.name;
	const itemId = params.id;
	const denied = requirePerm(user, "menus:manage");
	if (denied) return denied;
	if (!itemId) return apiError("VALIDATION_ERROR", "id is required", 400);
	const localeQ = parseQuery(new URL(request.url), localeFilterQuery);
	if (isParseError(localeQ)) return localeQ;
	try {
		return unwrapResult(await handleMenuItemDelete(emdash.db, name, itemId, { locale: localeQ.locale }));
	} catch (error) {
		return handleError(error, "Failed to delete menu item", "MENU_ITEM_DELETE_ERROR");
	}
};

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