import { x as head, c as escape_html, e as ensure_array_like, g as derived, b as attr_class } 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 } from './ui-DR8zOSpC.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 './no-face-up-DcejJLy-.js';
import '@cosmograph/cosmos';

//#region src/routes/code/flows/+page.svelte
function _page($$renderer, $$props) {
	$$renderer.component(($$renderer) => {
		let { data } = $$props;
		let selectedFlowId = null;
		const selectedFlow = derived(() => {
			const flows = data.flows;
			if (flows.length === 0) return null;
			const id = flows[0].id;
			return flows.find((f) => f.id === id) ?? flows[0];
		});
		const reachSet = derived(() => new Set(selectedFlow()?.reachIds ?? []));
		const graphModel = derived(() => {
			if (!selectedFlow()) return {
				nodes: [],
				edges: []
			};
			return {
				nodes: data.nodes.filter((n) => reachSet().has(n.id)).map((n) => ({
					id: n.id,
					substrate: "nexus",
					kind: n.kind || "symbol",
					label: n.label,
					category: n.id === selectedFlow().id ? "entry" : "reached",
					weight: n.id === selectedFlow().id ? 1 : .35,
					meta: { filePath: n.filePath }
				})),
				edges: data.edges.filter((e) => reachSet().has(e.source) && reachSet().has(e.target) && e.source !== e.target).map((e, idx) => ({
					id: `flow-${idx}-${e.source}-${e.target}`,
					source: e.source,
					target: e.target,
					kind: mapNexusRelationToEdgeKind(e.type),
					directional: true
				}))
			};
		});
		const stepEntries = derived(() => {
			if (!selectedFlow()) return [];
			const steps = data.edges.filter((e) => reachSet().has(e.source) && reachSet().has(e.target) && typeof e.stepIndex === "number").sort((a, b) => (a.stepIndex ?? 0) - (b.stepIndex ?? 0));
			const lookupLabel = (id) => data.nodes.find((n) => n.id === id)?.label ?? id;
			return steps.map((s) => ({
				source: lookupLabel(s.source),
				target: lookupLabel(s.target),
				type: s.type,
				stepIndex: s.stepIndex ?? 0
			}));
		});
		const flowsByKind = derived(() => {
			const groups = /* @__PURE__ */ new Map();
			for (const flow of data.flows) {
				const k = flow.kind || "other";
				const bucket = groups.get(k) ?? [];
				bucket.push(flow);
				groups.set(k, bucket);
			}
			return [...groups.entries()].sort((a, b) => b[1].length - a[1].length);
		});
		function onNodeClick(node) {
			if (node.id === selectedFlow()?.id) return;
			goto(`/code/symbol/${encodeURIComponent(node.label)}`);
		}
		const visibleEdgeKinds = new Set([
			"calls",
			"defines",
			"imports",
			"extends",
			"implements",
			"references",
			"has_method"
		]);
		head("1c4j9m0", $$renderer, ($$renderer) => {
			$$renderer.title(($$renderer) => {
				$$renderer.push(`<title>Execution Flows — Code — CLEO Studio</title>`);
			});
		});
		$$renderer.push(`<section class="flows-view svelte-1c4j9m0" aria-labelledby="flows-title"><header class="page-head svelte-1c4j9m0">`);
		Breadcrumb($$renderer, { items: [
			{
				label: "Studio",
				href: "/"
			},
			{
				label: "Code",
				href: "/code"
			},
			{ label: "Flows" }
		] });
		$$renderer.push(`<!----> <div class="title-row svelte-1c4j9m0"><div><span class="eyebrow svelte-1c4j9m0">NEXUS · Flows</span> <h1 id="flows-title" class="svelte-1c4j9m0">Execution Flows</h1> <p class="subtitle svelte-1c4j9m0">${escape_html(data.flows.length)} entry-points · ${escape_html(data.hasProcesses ? "process-annotated" : "call-graph derived")}</p></div></div></header> `);
		if (data.empty) {
			$$renderer.push("<!--[0-->");
			EmptyState($$renderer, {
				title: "No flows yet",
				subtitle: "Nexus hasn't captured any entry-points. Run cleo nexus analyze and ensure your project exposes entry-point symbols (functions with entry_point_of edges or high-out-degree call roots)."
			});
		} else {
			$$renderer.push("<!--[-1-->");
			$$renderer.push(`<div class="workbench svelte-1c4j9m0"><aside class="flow-list svelte-1c4j9m0" aria-label="Entry-point list">`);
			{
				function children($$renderer) {
					$$renderer.push(`<div class="list-stack svelte-1c4j9m0"><!--[-->`);
					const each_array = ensure_array_like(flowsByKind());
					for (let $$index_1 = 0, $$length = each_array.length; $$index_1 < $$length; $$index_1++) {
						let [kind, flows] = each_array[$$index_1];
						$$renderer.push(`<div class="group svelte-1c4j9m0"><h2 class="group-head svelte-1c4j9m0"><span class="kind-mark svelte-1c4j9m0" aria-hidden="true"></span> ${escape_html(kind)} <span class="group-count svelte-1c4j9m0">${escape_html(flows.length)}</span></h2> <ul class="svelte-1c4j9m0"><!--[-->`);
						const each_array_1 = ensure_array_like(flows);
						for (let $$index = 0, $$length = each_array_1.length; $$index < $$length; $$index++) {
							let flow = each_array_1[$$index];
							$$renderer.push(`<li><button type="button"${attr_class("flow-item svelte-1c4j9m0", void 0, { "active": selectedFlowId === flow.id })}><span class="flow-label svelte-1c4j9m0">${escape_html(flow.label)}</span> <span class="flow-sub svelte-1c4j9m0"><span>${escape_html(flow.reachIds.length - 1)} fanout</span> `);
							if (flow.filePath) {
								$$renderer.push("<!--[0-->");
								$$renderer.push(`<span class="sep svelte-1c4j9m0" aria-hidden="true">·</span> <span class="flow-path svelte-1c4j9m0">${escape_html(flow.filePath.split("/").slice(-2).join("/"))}</span>`);
							} else $$renderer.push("<!--[-1-->");
							$$renderer.push(`<!--]--></span></button></li>`);
						}
						$$renderer.push(`<!--]--></ul></div>`);
					}
					$$renderer.push(`<!--]--></div>`);
				}
				Card($$renderer, {
					elevation: 1,
					padding: "compact",
					children});
			}
			$$renderer.push(`<!----></aside> <div class="flow-stage svelte-1c4j9m0"><div class="stage svelte-1c4j9m0" aria-label="Selected flow canvas"><div class="stage-scanlines svelte-1c4j9m0" aria-hidden="true"></div> `);
			if (selectedFlow()) {
				$$renderer.push("<!--[0-->");
				CosmosRenderer($$renderer, {
					nodes: graphModel().nodes,
					edges: graphModel().edges,
					visibleEdgeKinds,
					showClusterLabels: false,
					onNodeClick,
					highlightNodeId: selectedFlow().id,
					height: "calc(100vh - 440px)",
					baseAlpha: .92
				});
			} else {
				$$renderer.push("<!--[-1-->");
				$$renderer.push(`<div class="placeholder svelte-1c4j9m0">Select an entry-point to trace.</div>`);
			}
			$$renderer.push(`<!--]--></div> <div class="timeline svelte-1c4j9m0" aria-label="Step timeline"><h2 class="group-head svelte-1c4j9m0"><span class="kind-mark kind-mark-timeline svelte-1c4j9m0" aria-hidden="true"></span> Timeline `);
			if (stepEntries().length > 0) {
				$$renderer.push("<!--[0-->");
				$$renderer.push(`<span class="group-count svelte-1c4j9m0">${escape_html(stepEntries().length)}</span>`);
			} else $$renderer.push("<!--[-1-->");
			$$renderer.push(`<!--]--></h2> `);
			if (stepEntries().length === 0) {
				$$renderer.push("<!--[0-->");
				$$renderer.push(`<p class="timeline-empty svelte-1c4j9m0">This flow has no explicit \`step_in_process\` ordering — the canvas above shows the BFS reach set instead.</p>`);
			} else {
				$$renderer.push("<!--[-1-->");
				$$renderer.push(`<ol class="timeline-list svelte-1c4j9m0"><!--[-->`);
				const each_array_2 = ensure_array_like(stepEntries());
				for (let i = 0, $$length = each_array_2.length; i < $$length; i++) {
					let step = each_array_2[i];
					$$renderer.push(`<li class="timeline-step svelte-1c4j9m0"><span class="step-idx svelte-1c4j9m0">${escape_html(step.stepIndex)}</span> <span class="step-arrow svelte-1c4j9m0" aria-hidden="true">→</span> <span class="step-body svelte-1c4j9m0"><span class="step-src svelte-1c4j9m0">${escape_html(step.source)}</span> <span class="step-sep svelte-1c4j9m0" aria-hidden="true">⟶</span> <span class="step-dst svelte-1c4j9m0">${escape_html(step.target)}</span> <span class="step-type svelte-1c4j9m0">${escape_html(step.type)}</span></span></li>`);
				}
				$$renderer.push(`<!--]--></ol>`);
			}
			$$renderer.push(`<!--]--></div></div></div>`);
		}
		$$renderer.push(`<!--]--></section>`);
	});
}

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