import { x as head, c as escape_html, e as ensure_array_like, b as attr_class, a as attr, d as attr_style, g as derived, f as stringify } from './dev-BNpEUZI3.js';
import { g as goto } from './client-CW9E6S_J.js';
import { a as Breadcrumb, C as Card } from './Tabs-DzG6Bn9a.js';
import { C as ChipGroup, b as Chip } from './ui-DR8zOSpC.js';
import { d as describeEdgeKind, E as EDGE_STYLE } from './no-face-up-DcejJLy-.js';
import { C as CosmosRenderer, b as adaptNexusRows } from './nexus-adapter-9EL_VlGI.js';
import './internal-DYSVC9SL.js';
import 'node:module';
import '@sveltejs/kit/internal';
import './index-server-DocJvixA.js';
import './chunk-DDP5xfzh.js';
import '@sveltejs/kit/internal/server';
import '@cosmograph/cosmos';

//#region src/routes/code/community/[id]/+page.svelte
function _page($$renderer, $$props) {
	$$renderer.component(($$renderer) => {
		let { data } = $$props;
		const adapted = derived(() => {
			return adaptNexusRows(data.nodes.map((n) => ({
				id: n.id,
				label: n.label,
				kind: n.kind,
				filePath: n.filePath,
				callerCount: n.callerCount,
				communityId: data.communityId
			})), data.edges.map((e) => ({
				source: e.source,
				target: e.target,
				type: e.type
			})));
		});
		const graphNodes = derived(() => adapted().nodes);
		const graphEdges = derived(() => adapted().edges);
		const graphClusters = derived(() => adapted().clusters);
		const COMMUNITY_EDGE_KINDS = [
			"calls",
			"extends",
			"implements",
			"has_method",
			"has_property",
			"defines",
			"imports",
			"accesses",
			"references"
		];
		const MEMBER_KINDS = [
			"class",
			"interface",
			"function",
			"method",
			"enum",
			"type_alias",
			"file"
		];
		let visibleEdgeKinds = new Set(COMMUNITY_EDGE_KINDS);
		let visibleNodeKinds = new Set(MEMBER_KINDS);
		let highlightedNodeId = null;
		let selectedNode = null;
		function toggleLabel(kind) {
			const next = new Set(visibleNodeKinds);
			if (next.has(kind)) next.delete(kind);
			else next.add(kind);
			visibleNodeKinds = next;
		}
		function onNodeClick(node) {
			selectedNode = node;
			if (node.kind !== "community") goto(`/code/symbol/${encodeURIComponent(node.label)}`);
		}
		const topMembers = derived(() => [...data.nodes].sort((a, b) => b.callerCount - a.callerCount).slice(0, 20));
		function shortPath(filePath) {
			return filePath.split("/").slice(-2).join("/");
		}
		const edgeKindCounts = derived(() => {
			const counts = /* @__PURE__ */ new Map();
			for (const e of graphEdges()) counts.set(e.kind, (counts.get(e.kind) ?? 0) + 1);
			return counts;
		});
		const nodeKindCounts = derived(() => {
			const counts = /* @__PURE__ */ new Map();
			for (const n of graphNodes()) counts.set(n.kind, (counts.get(n.kind) ?? 0) + 1);
			return counts;
		});
		head("1ewb8aw", $$renderer, ($$renderer) => {
			$$renderer.title(($$renderer) => {
				$$renderer.push(`<title>${escape_html(data.communityLabel)} — Code — CLEO Studio</title>`);
			});
		});
		$$renderer.push(`<section class="community-view svelte-1ewb8aw" aria-labelledby="community-title"><header class="page-head svelte-1ewb8aw">`);
		Breadcrumb($$renderer, { items: [
			{
				label: "Studio",
				href: "/"
			},
			{
				label: "Code",
				href: "/code"
			},
			{ label: data.communityLabel }
		] });
		$$renderer.push(`<!----> <div class="title-row svelte-1ewb8aw"><div><span class="eyebrow svelte-1ewb8aw">NEXUS · Community</span> <h1 id="community-title" class="svelte-1ewb8aw">${escape_html(data.communityLabel)}</h1> <p class="subtitle svelte-1ewb8aw"><span>${escape_html(data.summary.memberCount)} members</span> <span class="sep svelte-1ewb8aw" aria-hidden="true">·</span> <span>${escape_html(data.summary.internalEdgeCount)} internal edges</span> <span class="sep svelte-1ewb8aw" aria-hidden="true">·</span> <span>top kind: <span class="kind-badge svelte-1ewb8aw">${escape_html(data.summary.topKind)}</span></span></p></div></div></header> <div class="workbench svelte-1ewb8aw"><div class="stage svelte-1ewb8aw"><div class="stage-scanlines svelte-1ewb8aw" aria-hidden="true"></div> `);
		CosmosRenderer($$renderer, {
			nodes: graphNodes(),
			edges: graphEdges(),
			clusters: graphClusters(),
			visibleEdgeKinds,
			visibleNodeKinds,
			highlightNodeId: highlightedNodeId,
			showClusterLabels: false,
			onNodeClick,
			height: "calc(100vh - 220px)",
			baseAlpha: .92
		});
		$$renderer.push(`<!----> <footer class="legend-dock svelte-1ewb8aw" aria-label="Edge legend"><span class="legend-eyebrow svelte-1ewb8aw">EDGES (${escape_html(data.summary.internalEdgeCount)})</span> <ul class="svelte-1ewb8aw"><!--[-->`);
		const each_array = ensure_array_like(COMMUNITY_EDGE_KINDS);
		for (let $$index = 0, $$length = each_array.length; $$index < $$length; $$index++) {
			let kind = each_array[$$index];
			const style = EDGE_STYLE[kind];
			const active = visibleEdgeKinds.has(kind);
			const count = edgeKindCounts().get(kind) ?? 0;
			$$renderer.push(`<li><button type="button"${attr_class("legend-item svelte-1ewb8aw", void 0, {
				"active": active,
				"disabled": count === 0
			})}${attr("disabled", count === 0, true)}${attr("aria-pressed", active)}${attr("title", describeEdgeKind(kind))}><span${attr_class("swatch svelte-1ewb8aw", void 0, { "dashed": Boolean(style.dash) })} aria-hidden="true"${attr_style("", { background: style.color })}></span> <span class="legend-label">${escape_html(kind)}</span> <span class="legend-count svelte-1ewb8aw">${escape_html(count)}</span></button></li>`);
		}
		$$renderer.push(`<!--]--></ul></footer></div> <aside class="side-panel svelte-1ewb8aw" aria-label="Community controls">`);
		{
			function children($$renderer) {
				$$renderer.push(`<div class="panel-stack svelte-1ewb8aw"><div class="panel-section svelte-1ewb8aw"><h2 class="panel-head svelte-1ewb8aw">Member kinds</h2> `);
				{
					function children($$renderer) {
						$$renderer.push(`<!--[-->`);
						const each_array_1 = ensure_array_like(MEMBER_KINDS);
						for (let $$index_1 = 0, $$length = each_array_1.length; $$index_1 < $$length; $$index_1++) {
							let kind = each_array_1[$$index_1];
							const count = nodeKindCounts().get(kind) ?? 0;
							{
								function children($$renderer) {
									$$renderer.push(`<!---->${escape_html(kind)}`);
								}
								Chip($$renderer, {
									active: visibleNodeKinds.has(kind),
									disabled: count === 0,
									count,
									onclick: () => toggleLabel(kind),
									children,
									$$slots: { default: true }
								});
							}
						}
						$$renderer.push(`<!--]-->`);
					}
					ChipGroup($$renderer, {
						children});
				}
				$$renderer.push(`<!----></div> <div class="panel-section svelte-1ewb8aw"><h2 class="panel-head svelte-1ewb8aw">Top by callers</h2> <ol class="member-list svelte-1ewb8aw"><!--[-->`);
				const each_array_2 = ensure_array_like(topMembers());
				for (let $$index_2 = 0, $$length = each_array_2.length; $$index_2 < $$length; $$index_2++) {
					let m = each_array_2[$$index_2];
					$$renderer.push(`<li><a class="member-row svelte-1ewb8aw"${attr("href", `/code/symbol/${stringify(encodeURIComponent(m.label))}`)}><span class="member-label svelte-1ewb8aw">${escape_html(m.label)}</span> <span class="member-meta svelte-1ewb8aw"><span class="member-kind svelte-1ewb8aw">${escape_html(m.kind)}</span> `);
					if (m.filePath) {
						$$renderer.push("<!--[0-->");
						$$renderer.push(`<span class="member-path svelte-1ewb8aw">${escape_html(shortPath(m.filePath))}</span>`);
					} else $$renderer.push("<!--[-1-->");
					$$renderer.push(`<!--]--> <span class="member-count svelte-1ewb8aw">${escape_html(m.callerCount)}×</span></span></a></li>`);
				}
				$$renderer.push(`<!--]--></ol></div> `);
				if (selectedNode) {
					$$renderer.push("<!--[0-->");
					$$renderer.push(`<div class="panel-section svelte-1ewb8aw"><h2 class="panel-head svelte-1ewb8aw">Selected</h2> <div class="selected-card svelte-1ewb8aw"><span class="selected-label svelte-1ewb8aw">${escape_html(selectedNode.label)}</span> <span class="selected-kind svelte-1ewb8aw">${escape_html(selectedNode.kind)}</span> `);
					if (typeof selectedNode.meta?.filePath === "string") {
						$$renderer.push("<!--[0-->");
						$$renderer.push(`<span class="selected-meta svelte-1ewb8aw">${escape_html(shortPath(selectedNode.meta.filePath))}</span>`);
					} else $$renderer.push("<!--[-1-->");
					$$renderer.push(`<!--]--></div></div>`);
				} else $$renderer.push("<!--[-1-->");
				$$renderer.push(`<!--]--></div>`);
			}
			Card($$renderer, {
				elevation: 1,
				padding: "cozy",
				children});
		}
		$$renderer.push(`<!----></aside></div></section>`);
	});
}

export { _page as default };
//# sourceMappingURL=_page.svelte-CRmaDg9x.js.map
