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 } 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 { E as EmptyState, I as Input, 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, a as adaptNexusMacro, m as mapNexusRelationToEdgeKind } 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/+page.svelte
function _page($$renderer, $$props) {
	$$renderer.component(($$renderer) => {
		let { data } = $$props;
		const macroModel = derived(() => adaptNexusMacro(data.communities.map((c) => ({
			id: c.id,
			label: c.rawLabel,
			memberCount: c.size,
			topKind: c.topKind
		})), data.edges.map((e) => ({
			source: e.source,
			target: e.target,
			kind: mapNexusRelationToEdgeKind(e.dominantType),
			weight: e.weight
		}))));
		const graphNodes = derived(() => macroModel().nodes);
		const graphEdges = derived(() => macroModel().edges);
		const graphClusters = derived(() => macroModel().clusters);
		const CALL_EDGE_KINDS = [
			"contains",
			"defines",
			"imports",
			"calls",
			"extends",
			"implements",
			"has_method",
			"has_property",
			"member_of",
			"accesses",
			"references",
			"relates_to"
		];
		const LABEL_KINDS = [
			"community",
			"folder",
			"file",
			"class",
			"function",
			"method",
			"interface",
			"enum",
			"type_alias"
		];
		let visibleEdgeKinds = new Set(CALL_EDGE_KINDS);
		let visibleNodeKinds = new Set(LABEL_KINDS);
		let showClusterLabels = true;
		let highlightedNodeId = null;
		let selectedNode = null;
		function toggleEdge(kind) {
			const next = new Set(visibleEdgeKinds);
			if (next.has(kind)) next.delete(kind);
			else next.add(kind);
			visibleEdgeKinds = next;
		}
		function toggleLabel(kind) {
			const next = new Set(visibleNodeKinds);
			if (next.has(kind)) next.delete(kind);
			else next.add(kind);
			visibleNodeKinds = next;
		}
		let searchQuery = "";
		let searchResults = [];
		let searchDebounce = null;
		function onSearchInput() {
			if (searchDebounce) clearTimeout(searchDebounce);
			const q = searchQuery.trim();
			if (q.length < 2) {
				searchResults = [];
				return;
			}
			searchDebounce = setTimeout(async () => {
				try {
					const resp = await fetch(`/api/nexus/search?q=${encodeURIComponent(q)}`);
					if (!resp.ok) {
						searchResults = [];
						return;
					}
					searchResults = await resp.json();
				} catch {
					searchResults = [];
				}
			}, 180);
		}
		function onNodeClick(node) {
			selectedNode = node;
			if (node.kind === "community") goto(`/code/community/${encodeURIComponent(node.id)}`);
		}
		const topCommunities = derived(() => data.communities.slice(0, 12));
		function formatCount(n) {
			if (n >= 1e3) return `${(n / 1e3).toFixed(1)}k`;
			return String(n);
		}
		const totalEdgeWeight = derived(() => data.edges.reduce((s, e) => s + e.weight, 0));
		let $$settled = true;
		let $$inner_renderer;
		function $$render_inner($$renderer) {
			head("1cjo1uu", $$renderer, ($$renderer) => {
				$$renderer.title(($$renderer) => {
					$$renderer.push(`<title>Code Intelligence — CLEO Studio</title>`);
				});
			});
			$$renderer.push(`<section class="code-macro svelte-1cjo1uu" aria-labelledby="code-title"><header class="page-head svelte-1cjo1uu">`);
			Breadcrumb($$renderer, { items: [{
				label: "Studio",
				href: "/"
			}, { label: "Code" }] });
			$$renderer.push(`<!----> <div class="title-row svelte-1cjo1uu"><div class="title-block"><span class="eyebrow svelte-1cjo1uu">NEXUS · Macro</span> <h1 id="code-title" class="svelte-1cjo1uu">Code Intelligence</h1> <p class="subtitle svelte-1cjo1uu"><span class="stat-inline svelte-1cjo1uu">${escape_html(formatCount(data.totalNodes))} symbols</span> <span class="sep svelte-1cjo1uu" aria-hidden="true">·</span> <span class="stat-inline svelte-1cjo1uu">${escape_html(formatCount(data.totalRelations))} relations</span> <span class="sep svelte-1cjo1uu" aria-hidden="true">·</span> <span class="stat-inline svelte-1cjo1uu">${escape_html(data.communities.length)} communities</span></p></div> <div class="title-stats svelte-1cjo1uu" role="list" aria-label="Graph summary"><div class="stat-card svelte-1cjo1uu" role="listitem"><span class="stat-num svelte-1cjo1uu">${escape_html(formatCount(data.totalNodes))}</span> <span class="stat-lbl svelte-1cjo1uu">Symbols</span></div> <div class="stat-card svelte-1cjo1uu" role="listitem"><span class="stat-num svelte-1cjo1uu">${escape_html(formatCount(data.totalRelations))}</span> <span class="stat-lbl svelte-1cjo1uu">Relations</span></div> <div class="stat-card svelte-1cjo1uu" role="listitem"><span class="stat-num svelte-1cjo1uu">${escape_html(data.communities.length)}</span> <span class="stat-lbl svelte-1cjo1uu">Communities</span></div></div></div></header> `);
			if (data.empty) {
				$$renderer.push("<!--[0-->");
				EmptyState($$renderer, {
					title: "No code graph yet",
					subtitle: data.emptyReason ?? "Run cleo nexus analyze to populate nexus.db."
				});
			} else {
				$$renderer.push("<!--[-1-->");
				$$renderer.push(`<div class="workbench svelte-1cjo1uu"><div class="stage svelte-1cjo1uu"><div class="stage-scanlines svelte-1cjo1uu" aria-hidden="true"></div> `);
				CosmosRenderer($$renderer, {
					nodes: graphNodes(),
					edges: graphEdges(),
					clusters: graphClusters(),
					visibleEdgeKinds,
					visibleNodeKinds,
					highlightNodeId: highlightedNodeId,
					showClusterLabels,
					onNodeClick,
					height: "calc(100vh - 220px)",
					baseAlpha: .92
				});
				$$renderer.push(`<!----> <footer class="legend-dock svelte-1cjo1uu" aria-label="Edge legend"><span class="legend-eyebrow svelte-1cjo1uu">EDGE KINDS</span> <ul class="svelte-1cjo1uu"><!--[-->`);
				const each_array = ensure_array_like(CALL_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);
					$$renderer.push(`<li><button type="button"${attr_class("legend-item svelte-1cjo1uu", void 0, { "active": active })}${attr("aria-pressed", active)}${attr("title", describeEdgeKind(kind))}><span${attr_class("swatch svelte-1cjo1uu", void 0, { "dashed": Boolean(style.dash) })} aria-hidden="true"${attr_style("", { background: style.color })}></span> <span class="legend-label">${escape_html(kind)}</span> `);
					if (style.arrow) {
						$$renderer.push("<!--[0-->");
						$$renderer.push(`<span class="arrow-mark svelte-1cjo1uu" aria-hidden="true">›</span>`);
					} else $$renderer.push("<!--[-1-->");
					$$renderer.push(`<!--]--></button></li>`);
				}
				$$renderer.push(`<!--]--></ul></footer></div> <aside class="side-panel svelte-1cjo1uu" aria-label="Graph controls and details">`);
				{
					function children($$renderer) {
						$$renderer.push(`<div class="panel-stack svelte-1cjo1uu">`);
						Input($$renderer, {
							type: "search",
							label: "Search symbols",
							placeholder: "Search symbols, classes, functions…",
							oninput: onSearchInput,
							get value() {
								return searchQuery;
							},
							set value($$value) {
								searchQuery = $$value;
								$$settled = false;
							}
						});
						$$renderer.push(`<!----> `);
						if (searchResults.length > 0) {
							$$renderer.push("<!--[0-->");
							$$renderer.push(`<ul class="search-results svelte-1cjo1uu" role="listbox" aria-label="Search results"><!--[-->`);
							const each_array_1 = ensure_array_like(searchResults);
							for (let $$index_1 = 0, $$length = each_array_1.length; $$index_1 < $$length; $$index_1++) {
								let hit = each_array_1[$$index_1];
								$$renderer.push(`<li><button type="button" class="search-hit svelte-1cjo1uu"><span class="hit-label svelte-1cjo1uu">${escape_html(hit.label)}</span> <span class="hit-meta svelte-1cjo1uu"><span class="hit-kind svelte-1cjo1uu">${escape_html(hit.kind)}</span> `);
								if (hit.filePath) {
									$$renderer.push("<!--[0-->");
									$$renderer.push(`<span class="hit-path svelte-1cjo1uu">${escape_html(hit.filePath.split("/").slice(-2).join("/"))}</span>`);
								} else $$renderer.push("<!--[-1-->");
								$$renderer.push(`<!--]--></span></button></li>`);
							}
							$$renderer.push(`<!--]--></ul>`);
						} else if (searchQuery.trim().length >= 2) {
							$$renderer.push("<!--[1-->");
							$$renderer.push(`<p class="search-empty svelte-1cjo1uu">No matches for "${escape_html(searchQuery)}"</p>`);
						} else $$renderer.push("<!--[-1-->");
						$$renderer.push(`<!--]--> <div class="panel-section svelte-1cjo1uu"><h2 class="panel-head svelte-1cjo1uu">Visible Labels</h2> <p class="panel-hint svelte-1cjo1uu">Toggles WHICH kinds may render a cluster caption — never leaf labels.</p> `);
						{
							function children($$renderer) {
								$$renderer.push(`<!--[-->`);
								const each_array_2 = ensure_array_like(LABEL_KINDS);
								for (let $$index_2 = 0, $$length = each_array_2.length; $$index_2 < $$length; $$index_2++) {
									let kind = each_array_2[$$index_2];
									{
										function children($$renderer) {
											$$renderer.push(`<!---->${escape_html(kind)}`);
										}
										Chip($$renderer, {
											active: visibleNodeKinds.has(kind),
											onclick: () => toggleLabel(kind),
											children,
											$$slots: { default: true }
										});
									}
								}
								$$renderer.push(`<!--]-->`);
							}
							ChipGroup($$renderer, {
								children});
						}
						$$renderer.push(`<!----> <label class="toggle-row svelte-1cjo1uu"><input type="checkbox"${attr("checked", showClusterLabels, true)} class="svelte-1cjo1uu"/> <span>Show cluster captions</span></label></div> <div class="panel-section svelte-1cjo1uu"><h2 class="panel-head svelte-1cjo1uu">Visible Edges</h2> <p class="panel-hint svelte-1cjo1uu">Hides the kind entirely from the canvas.</p> `);
						{
							function children($$renderer) {
								$$renderer.push(`<!--[-->`);
								const each_array_3 = ensure_array_like(CALL_EDGE_KINDS);
								for (let $$index_3 = 0, $$length = each_array_3.length; $$index_3 < $$length; $$index_3++) {
									let kind = each_array_3[$$index_3];
									{
										function children($$renderer) {
											$$renderer.push(`<!---->${escape_html(kind)}`);
										}
										Chip($$renderer, {
											active: visibleEdgeKinds.has(kind),
											onclick: () => toggleEdge(kind),
											children,
											$$slots: { default: true }
										});
									}
								}
								$$renderer.push(`<!--]-->`);
							}
							ChipGroup($$renderer, {
								children});
						}
						$$renderer.push(`<!----></div> <div class="panel-section svelte-1cjo1uu"><h2 class="panel-head svelte-1cjo1uu">Top Communities</h2> <ul class="community-list svelte-1cjo1uu"><!--[-->`);
						const each_array_4 = ensure_array_like(topCommunities());
						for (let $$index_4 = 0, $$length = each_array_4.length; $$index_4 < $$length; $$index_4++) {
							let comm = each_array_4[$$index_4];
							$$renderer.push(`<li><a${attr("href", `/code/community/${encodeURIComponent(comm.id)}`)} class="community-row svelte-1cjo1uu"${attr_style("", { "--tint": comm.color })}><span class="tick svelte-1cjo1uu" aria-hidden="true"></span> <span class="row-body svelte-1cjo1uu"><span class="row-label svelte-1cjo1uu">${escape_html(comm.rawLabel)}</span> <span class="row-meta svelte-1cjo1uu">${escape_html(comm.size)} symbols · ${escape_html(comm.topKind)}</span></span> <span class="row-chev svelte-1cjo1uu" aria-hidden="true">→</span></a></li>`);
						}
						$$renderer.push(`<!--]--></ul></div> <div class="panel-section svelte-1cjo1uu"><a href="/code/flows" class="flow-link svelte-1cjo1uu"><span class="flow-arrow svelte-1cjo1uu" aria-hidden="true">▸</span> <span class="flow-body svelte-1cjo1uu"><span class="flow-title svelte-1cjo1uu">Execution Flows</span> <span class="flow-sub svelte-1cjo1uu">Trace entry-points through the call graph</span></span></a></div> `);
						if (selectedNode) {
							$$renderer.push("<!--[0-->");
							$$renderer.push(`<div class="panel-section selected svelte-1cjo1uu"><h2 class="panel-head svelte-1cjo1uu">Selected</h2> <div class="selected-card svelte-1cjo1uu"><span class="selected-label svelte-1cjo1uu">${escape_html(selectedNode.label)}</span> <span class="selected-kind svelte-1cjo1uu">${escape_html(selectedNode.kind)}</span> `);
							if (typeof selectedNode.meta?.memberCount === "number") {
								$$renderer.push("<!--[0-->");
								$$renderer.push(`<span class="selected-meta svelte-1cjo1uu">${escape_html(selectedNode.meta.memberCount)} members</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(`<!----> <div class="keyboard-list svelte-1cjo1uu" aria-label="Keyboard-accessible community list"><h2 class="panel-head sr-subhead svelte-1cjo1uu">All Communities</h2> <p class="panel-hint svelte-1cjo1uu">Keyboard-accessible mirror of the graph for screen readers and focus nav.</p> <ol class="svelte-1cjo1uu"><!--[-->`);
				const each_array_5 = ensure_array_like(data.communities);
				for (let $$index_5 = 0, $$length = each_array_5.length; $$index_5 < $$length; $$index_5++) {
					let comm = each_array_5[$$index_5];
					$$renderer.push(`<li><a${attr("href", `/code/community/${encodeURIComponent(comm.id)}`)} class="svelte-1cjo1uu"><span class="kb-label svelte-1cjo1uu">${escape_html(comm.rawLabel)}</span> <span class="kb-meta svelte-1cjo1uu">${escape_html(comm.size)} symbols · ${escape_html(comm.topKind)}</span></a></li>`);
				}
				$$renderer.push(`<!--]--></ol></div></aside></div> <p class="telemetry svelte-1cjo1uu" aria-hidden="true">Aggregate cross-community relations: ${escape_html(formatCount(totalEdgeWeight()))} · Top-600 shown ·
      Dominant-type preserved</p>`);
			}
			$$renderer.push(`<!--]--></section>`);
		}
		do {
			$$settled = true;
			$$inner_renderer = $$renderer.copy();
			$$render_inner($$inner_renderer);
		} while (!$$settled);
		$$renderer.subsume($$inner_renderer);
	});
}

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