import e from "../../../../lodash-es/forEach.js";
import t from "../../../../lodash-es/minBy.js";
import { Graph as n } from "../../graphlib/graph.js";
import "../../graphlib/index.js";
import { slack as r } from "./util.js";
//#region ../../node_modules/dagre-d3-es/src/dagre/rank/feasible-tree.js
function i(e) {
	var t = new n({ directed: !1 }), i = e.nodes()[0], c = e.nodeCount();
	t.setNode(i, {});
	for (var l, u; a(t, e) < c;) l = o(t, e), u = t.hasNode(l.v) ? r(e, l) : -r(e, l), s(t, e, u);
	return t;
}
function a(t, n) {
	function i(a) {
		e(n.nodeEdges(a), function(e) {
			var o = e.v, s = a === o ? e.w : o;
			!t.hasNode(s) && !r(n, e) && (t.setNode(s, {}), t.setEdge(a, s, {}), i(s));
		});
	}
	return e(t.nodes(), i), t.nodeCount();
}
function o(e, n) {
	return t(n.edges(), function(t) {
		if (e.hasNode(t.v) !== e.hasNode(t.w)) return r(n, t);
	});
}
function s(t, n, r) {
	e(t.nodes(), function(e) {
		n.node(e).rank += r;
	});
}
//#endregion
export { i as feasibleTree };
