import { ao as listAvailableAddonIds, ar as listEnabledAddonIds, ac as getRegistryAddonConfig, H as createLogger } from './src-CidJbygh.js';
import { g as getState } from './state-fxN45gBp.js';
import { d as getRequestId, r as requireAdmin, e as errorResponse, k as jsonResponse, p as parseJsonBody, j as jsonBodyError } 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/[name]/+server.ts
var logger = createLogger("addons.name");
var GET = async (event) => {
	const requestId = getRequestId(event);
	const authErr = requireAdmin(event, requestId);
	if (authErr) return authErr;
	const state = getState();
	const name = event.params.name;
	if (!listAvailableAddonIds().includes(name)) return errorResponse(404, "not_found", `Addon "${name}" is not available`, { name }, requestId);
	const enabled = listEnabledAddonIds(state.homeDir).includes(name);
	let config;
	try {
		config = getRegistryAddonConfig(name);
	} catch (error) {
		logger.error("failed to read addon schema", {
			name,
			error: String(error),
			requestId
		});
		return errorResponse(500, "internal_error", `Addon "${name}" schema is unavailable`, {}, requestId);
	}
	return jsonResponse(200, {
		name,
		enabled,
		config
	}, requestId);
};
var POST = async (event) => {
	const requestId = getRequestId(event);
	const authErr = requireAdmin(event, requestId);
	if (authErr) return authErr;
	const state = getState();
	const name = event.params.name;
	if (!listAvailableAddonIds().includes(name)) return errorResponse(404, "not_found", `Addon "${name}" is not available`, { name }, requestId);
	const result = await parseJsonBody(event.request);
	if ("error" in result) return jsonBodyError(result, requestId);
	const body = result.data;
	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-Bn2hwPxs.js.map
