import { error } from '@sveltejs/kit';

//#region src/routes/code/community/[id]/+page.server.ts
/**
* /code/community/[id] — server load.
*
* Wires through `/api/nexus/community/[id]` to retire the direct DB
* call flagged by the T990 code audit.  The API payload is passed to
* the adapter on the client, so this loader stays thin.
*
* @task T990
* @wave 1B
*/
var load = async ({ params, fetch }) => {
	const communityId = decodeURIComponent(params.id);
	const [detailResp, listResp] = await Promise.all([fetch(`/api/nexus/community/${encodeURIComponent(communityId)}`), fetch("/api/nexus?only=communities")]);
	if (!detailResp.ok) {
		if (detailResp.status === 404) error(404, `Community ${communityId} not found`);
		if (detailResp.status === 503) error(503, "nexus.db not available");
		error(detailResp.status, "Failed to load community");
	}
	const detail = await detailResp.json();
	let communityLabel = communityId.replace("comm_", "Cluster ");
	if (listResp.ok) {
		const match = (await listResp.json()).communities.find((c) => c.id === communityId);
		if (match?.rawLabel) communityLabel = match.rawLabel;
	}
	const kindHisto = /* @__PURE__ */ new Map();
	for (const n of detail.nodes) kindHisto.set(n.kind, (kindHisto.get(n.kind) ?? 0) + 1);
	let topKind = "function";
	let topCount = 0;
	for (const [k, c] of kindHisto) if (c > topCount) {
		topKind = k;
		topCount = c;
	}
	return {
		communityId,
		communityLabel,
		nodes: detail.nodes,
		edges: detail.edges,
		summary: {
			memberCount: detail.nodes.length,
			topKind,
			internalEdgeCount: detail.edges.length
		}
	};
};

var _page_server_ts = /*#__PURE__*/Object.freeze({
	__proto__: null,
	load: load
});

const index = 16;
let component_cache;
const component = async () => component_cache ??= (await import('./_page.svelte-CRmaDg9x.js')).default;
const server_id = "src/routes/code/community/[id]/+page.server.ts";
const imports = ["_app/immutable/nodes/16.DVrsYm5G.js","_app/immutable/chunks/CQQRJ2Hr.js","_app/immutable/chunks/DyGQ_VXC.js","_app/immutable/chunks/DrKWWDpL.js","_app/immutable/chunks/DKX-2-1g.js","_app/immutable/chunks/CQCxd1p9.js","_app/immutable/chunks/D8NsLz6i.js","_app/immutable/chunks/o1PZ6Kzq.js","_app/immutable/chunks/RptFUp2P.js","_app/immutable/chunks/CEqOYim7.js","_app/immutable/chunks/CqF5Lomf.js"];
const stylesheets = ["_app/immutable/assets/cluster-label-layer.aRgASjnn.css","_app/immutable/assets/no-face-up.BlswZ73M.css","_app/immutable/assets/nexus-adapter.DuSZKvuH.css","_app/immutable/assets/Tabs.CU9_rsWl.css","_app/immutable/assets/ui.CH-9N9-0.css","_app/immutable/assets/16.BzOs0cg_.css"];
const fonts = [];

export { component, fonts, imports, index, _page_server_ts as server, server_id, stylesheets };
//# sourceMappingURL=16-DTsdgXt3.js.map
