import { useWorkflow as e } from "../../../hooks/useWorkflows.js";
import { Background as t, BackgroundVariant as n, Controls as r, index as i, useEdgesState as a, useNodesState as o, useReactFlow as s } from "../../../node_modules/@xyflow/react/dist/esm/index.js";
/* empty css                                             */
import c from "./workflow-flow/StateNode.js";
import l from "./workflow-flow/WorkflowGraph.js";
import u from "./workflow-flow/WorkflowTransitionEdge.js";
import { useCallback as d, useEffect as f, useRef as p, useState as m } from "react";
import { jsx as h, jsxs as g } from "react/jsx-runtime";
import { Loader2 as _ } from "lucide-react";
//#region src/features/debug/components/WorkflowFlowViewer.tsx
var v = { stateNode: c }, y = { workflowTransition: u }, b = ({ workflowId: c, workflows: u, workflowConfig: b, direction: x = "LR" }) => {
	let { data: S } = e(c), [C, w, T] = o([]), [E, D, O] = a([]), { fitView: k } = s(), A = p(!1), [j, M] = m({}), N = p(/* @__PURE__ */ new Map()), P = Object.values(j).some((e) => e), F = d((e, t) => {
		M((n) => n[e] === t ? n : {
			...n,
			[e]: t
		});
	}, []), I = d((e, t, n) => {
		let r = u.findIndex((t) => t.id === e) * 250, i = t.map((e) => ({
			...e,
			position: {
				...e.position,
				y: e.position.y + r
			}
		}));
		N.current.set(e, {
			nodes: i,
			edges: n
		});
		let a = [], o = [];
		N.current.forEach(({ nodes: e, edges: t }) => {
			a.push(...e), o.push(...t);
		}), w(a), D(o);
	}, [
		u,
		w,
		D
	]);
	return f(() => {
		if (!P && C.length > 0 && !A.current) {
			A.current = !0;
			let e = setTimeout(() => {
				k({ padding: .2 });
			}, 150);
			return () => clearTimeout(e);
		}
	}, [
		P,
		C.length,
		k
	]), P && C.length === 0 ? /* @__PURE__ */ h("div", {
		className: "flex h-full items-center justify-center",
		children: /* @__PURE__ */ h(_, { className: "text-muted-foreground h-8 w-8 animate-spin" })
	}) : /* @__PURE__ */ g("div", {
		className: "h-full w-full",
		children: [S && u.map((e) => /* @__PURE__ */ h(l, {
			parentWorkflow: S,
			workflow: e,
			workflowConfig: b,
			onGraphReady: I,
			onLoadingChange: F,
			direction: x
		}, e.id)), C.length === 0 ? /* @__PURE__ */ h("div", {
			className: "text-muted-foreground flex h-full items-center justify-center",
			children: /* @__PURE__ */ h("p", {
				className: "font-medium",
				children: "No workflow transitions available"
			})
		}) : /* @__PURE__ */ g(i, {
			nodes: C,
			edges: E,
			onNodesChange: T,
			onEdgesChange: O,
			nodeTypes: v,
			edgeTypes: y,
			fitView: !0,
			minZoom: .1,
			maxZoom: 2,
			proOptions: { hideAttribution: !0 },
			className: "bg-background",
			children: [/* @__PURE__ */ h(t, {
				variant: n.Cross,
				gap: 24,
				size: 1,
				className: "opacity-[0.15]"
			}), /* @__PURE__ */ h(r, { className: "bg-card border-border rounded-lg border shadow-md" })]
		})]
	});
};
//#endregion
export { b as default };
