import e from "../../../lodash-es/constant.js";
import t from "../../../lodash-es/flatten.js";
import n from "../../../lodash-es/forEach.js";
import r from "../../../lodash-es/map.js";
import i from "../../../lodash-es/range.js";
import { Graph as a } from "../graphlib/graph.js";
import "../graphlib/index.js";
import { List as o } from "./data/list.js";
//#region ../../node_modules/dagre-d3-es/src/dagre/greedy-fas.js
var s = e(1);
function c(e, n) {
	if (e.nodeCount() <= 1) return [];
	var i = d(e, n || s);
	return t(r(l(i.graph, i.buckets, i.zeroIdx), function(t) {
		return e.outEdges(t.v, t.w);
	}));
}
function l(e, t, n) {
	for (var r = [], i = t[t.length - 1], a = t[0], o; e.nodeCount();) {
		for (; o = a.dequeue();) u(e, t, n, o);
		for (; o = i.dequeue();) u(e, t, n, o);
		if (e.nodeCount()) {
			for (var s = t.length - 2; s > 0; --s) if (o = t[s].dequeue(), o) {
				r = r.concat(u(e, t, n, o, !0));
				break;
			}
		}
	}
	return r;
}
function u(e, t, r, i, a) {
	var o = a ? [] : void 0;
	return n(e.inEdges(i.v), function(n) {
		var i = e.edge(n), s = e.node(n.v);
		a && o.push({
			v: n.v,
			w: n.w
		}), s.out -= i, f(t, r, s);
	}), n(e.outEdges(i.v), function(n) {
		var i = e.edge(n), a = n.w, o = e.node(a);
		o.in -= i, f(t, r, o);
	}), e.removeNode(i.v), o;
}
function d(e, t) {
	var r = new a(), s = 0, c = 0;
	n(e.nodes(), function(e) {
		r.setNode(e, {
			v: e,
			in: 0,
			out: 0
		});
	}), n(e.edges(), function(e) {
		var n = r.edge(e.v, e.w) || 0, i = t(e), a = n + i;
		r.setEdge(e.v, e.w, a), c = Math.max(c, r.node(e.v).out += i), s = Math.max(s, r.node(e.w).in += i);
	});
	var l = i(c + s + 3).map(function() {
		return new o();
	}), u = s + 1;
	return n(r.nodes(), function(e) {
		f(l, u, r.node(e));
	}), {
		graph: r,
		buckets: l,
		zeroIdx: u
	};
}
function f(e, t, n) {
	n.out ? n.in ? e[n.out - n.in + t].enqueue(n) : e[e.length - 1].enqueue(n) : e[0].enqueue(n);
}
//#endregion
export { c as greedyFAS };

//# sourceMappingURL=greedy-fas.js.map