import "../../../../../../base64-CmWvODNW.mjs";
import "../../../../../../types-CuW0zWDA.mjs";
import { a as unwrapResult, t as apiError } from "../../../../../../error-CkAseSqZ.mjs";
import { n as requirePerm } from "../../../../../../authorize-Dz88F_Fw.mjs";
import { hasPermission } from "@emdash-cms/auth";

//#region src/astro/routes/api/content/[collection]/[id]/translations.ts
/**
* Content translations endpoint
*
* GET /_emdash/api/content/{collection}/{id}/translations
*
* Returns all locale variants linked to the same translation group.
*/
const prerender = false;
function isPublished(t) {
	return typeof t === "object" && t !== null && "status" in t && t.status === "published";
}
const GET = async ({ params, locals }) => {
	const { emdash, user } = locals;
	const denied = requirePerm(user, "content:read");
	if (denied) return denied;
	const collection = params.collection;
	const id = params.id;
	if (!emdash?.handleContentTranslations) return apiError("NOT_CONFIGURED", "EmDash is not initialized", 500);
	const result = await emdash.handleContentTranslations(collection, id);
	if (result.success && !hasPermission(user, "content:read_drafts")) {
		const data = result.data && typeof result.data === "object" ? result.data : void 0;
		const filtered = (Array.isArray(data?.translations) ? data.translations : []).filter(isPublished);
		return unwrapResult({
			success: true,
			data: {
				...data,
				translations: filtered
			}
		});
	}
	return unwrapResult(result);
};

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