import { a9 as getAkmStats } from './src-CidJbygh.js';
import { g as getState } from './state-fxN45gBp.js';
import { d as getRequestId, r as requireAdmin, k as jsonResponse, e as errorResponse } from './helpers-kzwksNq1.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/akm/stats/+server.ts
var CACHE_TTL_MS = 15e3;
var cachedStats = null;
var cachedAt = 0;
var inFlight = null;
function _resetStatsCacheForTests() {
	cachedStats = null;
	cachedAt = 0;
	inFlight = null;
}
var GET = async (event) => {
	const requestId = getRequestId(event);
	const denied = requireAdmin(event, requestId);
	if (denied) return denied;
	if (cachedStats && Date.now() - cachedAt < CACHE_TTL_MS) return jsonResponse(200, cachedStats, requestId);
	try {
		if (!inFlight) inFlight = getAkmStats(getState()).finally(() => {
			inFlight = null;
		});
		const stats = await inFlight;
		cachedStats = stats;
		cachedAt = Date.now();
		return jsonResponse(200, stats, requestId);
	} catch (error) {
		return errorResponse(500, "akm_stats_failed", error instanceof Error ? error.message : "Failed to load AKM stats.", {}, requestId);
	}
};

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