import { useWorkflow as e, useWorkflowCheckpoints as t } from "../../../../hooks/useWorkflows.js";
import { buildWorkflowGraph as n, getTransitions as r } from "../../lib/flow-utils.js";
import { useEffect as i, useRef as a } from "react";
//#region src/features/debug/components/workflow-flow/WorkflowGraph.tsx
function o(e) {
	return e ? r(e).length : 0;
}
var s = ({ parentWorkflow: s, workflow: c, workflowConfig: l, onGraphReady: u, onLoadingChange: d, direction: f = "LR" }) => {
	let p = e(c.id), m = p.data, h = t(c.id), g = h.data ?? [], _ = a(null), v = p.isLoading || h.isLoading;
	return i(() => {
		d(c.id, v);
	}, [
		c.id,
		v,
		d
	]), i(() => {
		if (v) return;
		let e = l ? r(l) : [], t = JSON.stringify({
			p: o(s),
			w: o(m),
			c: e.length,
			checkpoints: g.length,
			place: m?.place
		});
		if (t !== _.current) {
			_.current = t;
			let { nodes: r, edges: i } = n(s, m, c.id, e, f, !1, g);
			u(c.id, r, i);
		}
	}, [
		s,
		c,
		m,
		g,
		l,
		u,
		v
	]), null;
};
//#endregion
export { s as default };
