import { Background, BackgroundVariant, Controls, index, useEdgesState, useNodesState, useReactFlow } from "../../../node_modules/@xyflow/react/dist/esm/index.js";
/* empty css                                             */
import { buildWorkflowGraph } from "../lib/flow-utils.js";
import StateNode_default from "./pipeline-flow/StateNode.js";
import WorkflowTransitionEdge_default from "./pipeline-flow/WorkflowTransitionEdge.js";
import { c } from "react/compiler-runtime";
import React, { useEffect, useRef } from "react";
import { jsx, jsxs } from "react/jsx-runtime";
import { Loader2 } from "lucide-react";
var nodeTypes = { stateNode: StateNode_default }, edgeTypes = { workflowTransition: WorkflowTransitionEdge_default }, ConfigFlowViewer_default = (_) => {
	let v = c(21), { config: y } = _, b;
	v[0] === Symbol.for("react.memo_cache_sentinel") ? (b = [], v[0] = b) : b = v[0];
	let [x, S, C] = useNodesState(b), w;
	v[1] === Symbol.for("react.memo_cache_sentinel") ? (w = [], v[1] = w) : w = v[1];
	let [T, E, D] = useEdgesState(w), { fitView: O } = useReactFlow(), k = useRef(!1), A, j;
	v[2] !== y || v[3] !== E || v[4] !== S ? (A = () => {
		if (!y) return;
		let { nodes: e, edges: g } = buildWorkflowGraph(y, void 0, "preview", y.transitions ?? [], "TB", !0);
		S(e), E(g);
	}, j = [
		y,
		S,
		E
	], v[2] = y, v[3] = E, v[4] = S, v[5] = A, v[6] = j) : (A = v[5], j = v[6]), useEffect(A, j);
	let M, N;
	if (v[7] !== O || v[8] !== x.length ? (M = () => {
		if (x.length > 0 && !k.current) {
			k.current = !0;
			let e = setTimeout(() => {
				O({ padding: .2 });
			}, 150);
			return () => clearTimeout(e);
		}
	}, N = [x.length, O], v[7] = O, v[8] = x.length, v[9] = M, v[10] = N) : (M = v[9], N = v[10]), useEffect(M, N), !y) {
		let e;
		return v[11] === Symbol.for("react.memo_cache_sentinel") ? (e = /* @__PURE__ */ jsx("div", {
			className: "flex h-full items-center justify-center",
			children: /* @__PURE__ */ jsx(Loader2, { className: "h-6 w-6 animate-spin text-muted-foreground" })
		}), v[11] = e) : e = v[11], e;
	}
	if (x.length === 0) {
		let e;
		return v[12] === Symbol.for("react.memo_cache_sentinel") ? (e = /* @__PURE__ */ jsx("div", {
			className: "text-muted-foreground flex h-full items-center justify-center",
			children: /* @__PURE__ */ jsx("p", {
				className: "font-medium",
				children: "No transitions defined in configuration"
			})
		}), v[12] = e) : e = v[12], e;
	}
	let P;
	v[13] === Symbol.for("react.memo_cache_sentinel") ? (P = { hideAttribution: !0 }, v[13] = P) : P = v[13];
	let F, I;
	v[14] === Symbol.for("react.memo_cache_sentinel") ? (F = /* @__PURE__ */ jsx(Background, {
		variant: BackgroundVariant.Cross,
		gap: 24,
		size: 1,
		className: "opacity-[0.15]"
	}), I = /* @__PURE__ */ jsx(Controls, { className: "bg-card border-border rounded-lg border shadow-md" }), v[14] = F, v[15] = I) : (F = v[14], I = v[15]);
	let L;
	return v[16] !== T || v[17] !== x || v[18] !== D || v[19] !== C ? (L = /* @__PURE__ */ jsx("div", {
		className: "h-full w-full bg-background",
		children: /* @__PURE__ */ jsxs(index, {
			nodes: x,
			edges: T,
			onNodesChange: C,
			onEdgesChange: D,
			nodeTypes,
			edgeTypes,
			fitView: !0,
			minZoom: .1,
			maxZoom: 2,
			proOptions: P,
			className: "bg-background",
			children: [F, I]
		})
	}), v[16] = T, v[17] = x, v[18] = D, v[19] = C, v[20] = L) : L = v[20], L;
};
export { ConfigFlowViewer_default as default };
