import { x as head, c as escape_html, b as attr_class, e as ensure_array_like, 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, T as Tabs } from './Tabs-DzG6Bn9a.js';
import { c as TabPanel } from './ui-DR8zOSpC.js';
import { d as describeEdgeKind, E as EDGE_STYLE } from './no-face-up-DcejJLy-.js';
import { C as CosmosRenderer, 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/symbol/[name]/+page.svelte
function _page($$renderer, $$props) {
	$$renderer.component(($$renderer) => {
		let { data } = $$props;
		let colorMode = "hop";
		/**
		* Hop colour → semantic CSS token.
		*    hop 0 — amber  (self)
		*    hop 1 — info   (direct neighbours)
		*    hop 2 — faint  (two-hop ring)
		*/
		const HOP_TOKEN = {
			0: "var(--warning)",
			1: "var(--info)",
			2: "var(--text-faint)"
		};
		const graphModel = derived(() => {
			const nodes = data.nodes.map((n) => {
				const tint = colorMode === "hop" ? HOP_TOKEN[n.hop] : void 0;
				const meta = {
					hop: n.hop,
					filePath: n.filePath,
					callerCount: n.callerCount
				};
				if (tint) meta.colorOverride = tint;
				return {
					id: n.id,
					substrate: "nexus",
					kind: n.kind || "symbol",
					label: n.label,
					category: n.communityId ?? null,
					weight: Math.min(1, Math.log10(n.callerCount + 1) / 3),
					meta
				};
			});
			const validIds = new Set(nodes.map((n) => n.id));
			return {
				nodes,
				edges: data.edges.filter((e) => validIds.has(e.source) && validIds.has(e.target) && e.source !== e.target).map((e, idx) => {
					const kind = mapNexusRelationToEdgeKind(e.type);
					return {
						id: `ego-${idx}-${e.source}-${e.target}-${kind}`,
						source: e.source,
						target: e.target,
						kind,
						directional: true
					};
				})
			};
		});
		const graphNodes = derived(() => graphModel().nodes);
		const graphEdges = derived(() => graphModel().edges);
		const EGO_EDGE_KINDS = [
			"calls",
			"extends",
			"implements",
			"defines",
			"imports",
			"has_method",
			"has_property",
			"accesses",
			"references"
		];
		let visibleEdgeKinds = new Set(EGO_EDGE_KINDS);
		const callerNodes = derived(() => data.nodes.filter((n) => {
			if (n.hop !== 1) return false;
			return data.edges.some((e) => e.target === data.center?.id && e.source === n.id);
		}));
		const calleeNodes = derived(() => data.nodes.filter((n) => {
			if (n.hop !== 1) return false;
			return data.edges.some((e) => e.source === data.center?.id && e.target === n.id);
		}));
		const hop2Count = derived(() => data.nodes.filter((n) => n.hop === 2).length);
		function onNodeClick(node) {
			if (node.id !== data.center?.id) goto(`/code/symbol/${encodeURIComponent(node.label)}`);
		}
		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;
		});
		function shortPath(filePath) {
			return filePath.split("/").slice(-2).join("/");
		}
		const breadcrumbs = derived(() => [
			{
				label: "Studio",
				href: "/"
			},
			{
				label: "Code",
				href: "/code"
			},
			...data.center?.communityId && data.communityLabel ? [{
				label: data.communityLabel,
				href: `/code/community/${encodeURIComponent(data.center.communityId)}`
			}] : [],
			{ label: data.symbolName }
		]);
		head("16icikf", $$renderer, ($$renderer) => {
			$$renderer.title(($$renderer) => {
				$$renderer.push(`<title>${escape_html(data.symbolName)} — Code — CLEO Studio</title>`);
			});
		});
		$$renderer.push(`<section class="symbol-view svelte-16icikf" aria-labelledby="symbol-title"><header class="page-head svelte-16icikf">`);
		Breadcrumb($$renderer, { items: breadcrumbs() });
		$$renderer.push(`<!----> <div class="title-row svelte-16icikf"><div><span class="eyebrow svelte-16icikf">NEXUS · Ego</span> <h1 id="symbol-title" class="sym-title svelte-16icikf">${escape_html(data.symbolName)}</h1> <p class="subtitle svelte-16icikf">`);
		if (data.center) {
			$$renderer.push("<!--[0-->");
			$$renderer.push(`<span class="kind-badge svelte-16icikf">${escape_html(data.center.kind)}</span> `);
			if (data.center.filePath) {
				$$renderer.push("<!--[0-->");
				$$renderer.push(`<span class="sep svelte-16icikf" aria-hidden="true">·</span> <span class="path svelte-16icikf">${escape_html(data.center.filePath)}</span>`);
			} else $$renderer.push("<!--[-1-->");
			$$renderer.push(`<!--]-->`);
		} else $$renderer.push("<!--[-1-->");
		$$renderer.push(`<!--]--></p></div> <div class="stat-row svelte-16icikf"><div class="stat callers-stat svelte-16icikf"><span class="stat-num svelte-16icikf">${escape_html(callerNodes().length)}</span> <span class="stat-lbl svelte-16icikf">Callers</span></div> <div class="stat callees-stat svelte-16icikf"><span class="stat-num svelte-16icikf">${escape_html(calleeNodes().length)}</span> <span class="stat-lbl svelte-16icikf">Callees</span></div> <div class="stat svelte-16icikf"><span class="stat-num svelte-16icikf">${escape_html(hop2Count())}</span> <span class="stat-lbl svelte-16icikf">Hop-2</span></div></div></div></header> <div class="workbench svelte-16icikf"><div${attr_class("stage svelte-16icikf", void 0, { "mode-hop": colorMode === "hop" })}><div class="stage-scanlines svelte-16icikf" aria-hidden="true"></div> `);
		if (colorMode === "hop") {
			$$renderer.push("<!--[0-->");
			$$renderer.push(`<div class="hop-rings svelte-16icikf" aria-hidden="true"><span class="ring ring-1 svelte-16icikf"></span> <span class="ring ring-2 svelte-16icikf"></span></div>`);
		} else $$renderer.push("<!--[-1-->");
		$$renderer.push(`<!--]--> `);
		CosmosRenderer($$renderer, {
			nodes: graphNodes(),
			edges: graphEdges(),
			visibleEdgeKinds,
			onNodeClick,
			showClusterLabels: false,
			height: "calc(100vh - 220px)",
			baseAlpha: .94
		});
		$$renderer.push(`<!----> <footer class="legend-dock svelte-16icikf" aria-label="Edge legend"><span class="legend-eyebrow svelte-16icikf">EDGES</span> <ul class="svelte-16icikf"><!--[-->`);
		const each_array = ensure_array_like(EGO_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-16icikf", 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-16icikf", void 0, { "dashed": Boolean(style.dash) })} aria-hidden="true"${attr_style("", { background: style.color })}></span> <span>${escape_html(kind)}</span> <span class="legend-count svelte-16icikf">${escape_html(count)}</span></button></li>`);
		}
		$$renderer.push(`<!--]--></ul></footer></div> <aside class="side-panel svelte-16icikf" aria-label="Ego network details">`);
		{
			function children($$renderer) {
				$$renderer.push(`<div class="panel-stack svelte-16icikf">`);
				Tabs($$renderer, {
					items: [{
						value: "hop",
						label: "Hop coloring"
					}, {
						value: "kind",
						label: "Kind coloring"
					}],
					value: colorMode,
					onchange: (v) => {
						colorMode = v === "kind" ? "kind" : "hop";
					}
				});
				$$renderer.push(`<!----> `);
				{
					function children($$renderer) {
						$$renderer.push(`<p class="panel-hint svelte-16icikf">Center = amber · hop-1 = blue · hop-2 = slate.</p>`);
					}
					TabPanel($$renderer, {
						value: "hop",
						active: colorMode,
						children});
				}
				$$renderer.push(`<!----> `);
				{
					function children($$renderer) {
						$$renderer.push(`<p class="panel-hint svelte-16icikf">Substrate-native palette — matches macro + community views.</p>`);
					}
					TabPanel($$renderer, {
						value: "kind",
						active: colorMode,
						children});
				}
				$$renderer.push(`<!----> `);
				if (callerNodes().length > 0) {
					$$renderer.push("<!--[0-->");
					$$renderer.push(`<div class="panel-section svelte-16icikf"><h2 class="panel-head svelte-16icikf"><span class="dot dot-caller svelte-16icikf" aria-hidden="true"></span> Callers (${escape_html(callerNodes().length)})</h2> <ul class="chip-list svelte-16icikf"><!--[-->`);
					const each_array_1 = ensure_array_like(callerNodes());
					for (let $$index_1 = 0, $$length = each_array_1.length; $$index_1 < $$length; $$index_1++) {
						let node = each_array_1[$$index_1];
						$$renderer.push(`<li><a${attr("href", `/code/symbol/${encodeURIComponent(node.label)}`)} class="chip chip-caller svelte-16icikf"><span class="chip-label svelte-16icikf">${escape_html(node.label)}</span> <span class="chip-kind svelte-16icikf">${escape_html(node.kind)}</span></a></li>`);
					}
					$$renderer.push(`<!--]--></ul></div>`);
				} else $$renderer.push("<!--[-1-->");
				$$renderer.push(`<!--]--> `);
				if (calleeNodes().length > 0) {
					$$renderer.push("<!--[0-->");
					$$renderer.push(`<div class="panel-section svelte-16icikf"><h2 class="panel-head svelte-16icikf"><span class="dot dot-callee svelte-16icikf" aria-hidden="true"></span> Callees (${escape_html(calleeNodes().length)})</h2> <ul class="chip-list svelte-16icikf"><!--[-->`);
					const each_array_2 = ensure_array_like(calleeNodes());
					for (let $$index_2 = 0, $$length = each_array_2.length; $$index_2 < $$length; $$index_2++) {
						let node = each_array_2[$$index_2];
						$$renderer.push(`<li><a${attr("href", `/code/symbol/${encodeURIComponent(node.label)}`)} class="chip chip-callee svelte-16icikf"><span class="chip-label svelte-16icikf">${escape_html(node.label)}</span> <span class="chip-kind svelte-16icikf">${escape_html(node.kind)}</span></a></li>`);
					}
					$$renderer.push(`<!--]--></ul></div>`);
				} else $$renderer.push("<!--[-1-->");
				$$renderer.push(`<!--]--> `);
				if (data.center?.filePath) {
					$$renderer.push("<!--[0-->");
					$$renderer.push(`<div class="panel-section svelte-16icikf"><h2 class="panel-head svelte-16icikf">File</h2> <p class="file-path svelte-16icikf"${attr("title", data.center.filePath)}>${escape_html(shortPath(data.center.filePath))}</p></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-VtPkM6fK.js.map
