import "../../../../../../dialect-helpers-DRI5pyY3.mjs";
import "../../../../../../after-B1IIdH3Y.mjs";
import "../../../../../../object-cache-Bok5j2ae.mjs";
import "../../../../../../base64-CmWvODNW.mjs";
import "../../../../../../types-CuW0zWDA.mjs";
import "../../../../../../request-cache-KCNHp_RJ.mjs";
import "../../../../../../byline-registry-BOjqDOim.mjs";
import "../../../../../../field-defs-cache-WUI88LX5.mjs";
import { t as BylineRepository } from "../../../../../../byline-Bm8ZgUP9.mjs";
import "../../../../../../loader-CB6YHeul.mjs";
import "../../../../../../resolve-DR3wqMTy.mjs";
import { a as unwrapResult, i as requireDb, r as handleError } from "../../../../../../error-CkAseSqZ.mjs";
import { n as parseBody, t as isParseError } from "../../../../../../parse-GmjecGct.mjs";
import { Cn as bylineTranslationCreateBody } from "../../../../../../redirects-DXEXBAII.mjs";
import "../../../../../../byline-fields-2Lp5Hbgf.mjs";
import "../../../../../../status-CqJQX1QN.mjs";
import "../../../../../../api/schemas/index.mjs";
import { a as invalidateBylineCache } from "../../../../../../bylines-Woq87129.mjs";
import { n as requirePerm } from "../../../../../../authorize-Dz88F_Fw.mjs";
import { n as handleBylineCreate, r as handleBylineTranslations } from "../../../../../../bylines-6tm9mgQb.mjs";

//#region src/astro/routes/api/admin/bylines/[id]/translations.ts
const prerender = false;
const GET = async ({ params, locals }) => {
	const { emdash, user } = locals;
	const id = params.id;
	const dbErr = requireDb(emdash?.db);
	if (dbErr) return dbErr;
	const denied = requirePerm(user, "bylines:read");
	if (denied) return denied;
	try {
		return unwrapResult(await handleBylineTranslations(emdash.db, id));
	} catch (error) {
		return handleError(error, "Failed to fetch byline translations", "BYLINE_TRANSLATIONS_ERROR");
	}
};
const POST = async ({ params, request, locals }) => {
	const { emdash, user } = locals;
	const id = params.id;
	const dbErr = requireDb(emdash?.db);
	if (dbErr) return dbErr;
	const denied = requirePerm(user, "bylines:manage");
	if (denied) return denied;
	try {
		const body = await parseBody(request, bylineTranslationCreateBody);
		if (isParseError(body)) return body;
		const source = await new BylineRepository(emdash.db).findById(id);
		if (!source) return new Response(JSON.stringify({ error: {
			code: "NOT_FOUND",
			message: "Byline not found"
		} }), {
			status: 404,
			headers: { "Content-Type": "application/json" }
		});
		const result = await handleBylineCreate(emdash.db, {
			slug: body.slug ?? source.slug,
			displayName: body.displayName ?? source.displayName,
			bio: body.bio ?? null,
			avatarMediaId: body.avatarMediaId ?? source.avatarMediaId,
			websiteUrl: body.websiteUrl ?? source.websiteUrl,
			userId: null,
			isGuest: source.isGuest,
			locale: body.locale,
			translationOf: id
		});
		if (result.success) /* @__PURE__ */ invalidateBylineCache();
		return unwrapResult(result, 201);
	} catch (error) {
		return handleError(error, "Failed to create byline translation", "BYLINE_TRANSLATION_CREATE_ERROR");
	}
};

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