import { ar as listEnabledAddonIds, ao as listAvailableAddonIds } from './src-CidJbygh.js';
import { g as getState } from './state-fxN45gBp.js';
import { d as getRequestId, r as requireAdmin, k as jsonResponse, p as parseJsonBody, j as jsonBodyError, e as errorResponse } from './helpers-kzwksNq1.js';
import { p as performAddonToggle } from './addon-helpers-CtXSmg5a.js';
import './chunk-CLZ62Ad-.js';
import 'node:module';
import './provider-constants-DPrj3yBX.js';
import './dist-DOFcG0Zp.js';
import 'node:fs';
import 'node:path';
import 'buffer';
import 'fs';
import 'path';
import 'node:child_process';
import 'node:url';
import 'node:crypto';
import 'events';
import 'node:events';
import 'node:stream';
import 'node:string_decoder';
import 'assert';
import 'zlib';
import 'node:assert';
import 'node:fs/promises';
import 'node:os';
import './endpoints-UdQGgKsR.js';

//#region src/routes/admin/addons/+server.ts
function buildAddonList(availableIds, enabledIds) {
	const enabledSet = new Set(enabledIds);
	return availableIds.map((name) => ({
		name,
		enabled: enabledSet.has(name),
		available: true
	}));
}
var GET = async (event) => {
	const requestId = getRequestId(event);
	const authErr = requireAdmin(event, requestId);
	if (authErr) return authErr;
	const state = getState();
	return jsonResponse(200, { addons: buildAddonList(listAvailableAddonIds(), listEnabledAddonIds(state.homeDir)) }, requestId);
};
var POST = async (event) => {
	const requestId = getRequestId(event);
	const authErr = requireAdmin(event, requestId);
	if (authErr) return authErr;
	const state = getState();
	const result = await parseJsonBody(event.request);
	if ("error" in result) return jsonBodyError(result, requestId);
	const body = result.data;
	const name = typeof body.name === "string" ? body.name.trim() : "";
	if (!name) return errorResponse(400, "bad_request", "name is required", {}, requestId);
	if (!listAvailableAddonIds().includes(name)) return errorResponse(404, "not_found", `Addon "${name}" is not available`, { name }, requestId);
	const toggle = await performAddonToggle(state, name, typeof body.enabled === "boolean" ? body.enabled : void 0, requestId);
	if (!toggle.ok) return errorResponse(500, "internal_error", toggle.error, {}, requestId);
	return jsonResponse(200, {
		ok: true,
		addon: name,
		enabled: toggle.enabled,
		changed: toggle.changed
	}, requestId);
};

export { GET, POST };
//# sourceMappingURL=_server.ts-DM9CM7r4.js.map
