import "../../../../../../base64-CmWvODNW.mjs";
import "../../../../../../types-CuW0zWDA.mjs";
import { n as apiSuccess, r as handleError, t as apiError } from "../../../../../../error-CkAseSqZ.mjs";
import { createKyselyAdapter } from "@emdash-cms/auth/adapters/kysely";
import { Role } from "@emdash-cms/auth";

//#region src/astro/routes/api/admin/users/[id]/enable.ts
/**
* User enable endpoint
*
* POST /_emdash/api/admin/users/:id/enable - Re-enable a disabled user
*/
const prerender = false;
const POST = async ({ params, locals }) => {
	const { emdash, user } = locals;
	if (!emdash?.db) return apiError("NOT_CONFIGURED", "Database not configured", 500);
	if (!user || user.role < Role.ADMIN) return apiError("FORBIDDEN", "Admin privileges required", 403);
	const adapter = createKyselyAdapter(emdash.db);
	const { id } = params;
	if (!id) return apiError("VALIDATION_ERROR", "User ID required", 400);
	try {
		if (!await adapter.getUserById(id)) return apiError("NOT_FOUND", "User not found", 404);
		await adapter.updateUser(id, { disabled: false });
		return apiSuccess({ success: true });
	} catch (error) {
		return handleError(error, "Failed to enable user", "USER_ENABLE_ERROR");
	}
};

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