import e from "../../../../lodash-es/flatten.js";
import t from "../../../../lodash-es/forEach.js";
import n from "../../../../lodash-es/last.js";
import r from "../../../../lodash-es/sortBy.js";
import { partition as i } from "../util.js";
//#region ../../node_modules/dagre-d3-es/src/dagre/order/sort.js
function a(n, a) {
	var c = i(n, function(e) {
		return Object.prototype.hasOwnProperty.call(e, "barycenter");
	}), l = c.lhs, u = r(c.rhs, function(e) {
		return -e.i;
	}), d = [], f = 0, p = 0, m = 0;
	l.sort(s(!!a)), m = o(d, u, m), t(l, function(e) {
		m += e.vs.length, d.push(e.vs), f += e.barycenter * e.weight, p += e.weight, m = o(d, u, m);
	});
	var h = { vs: e(d) };
	return p && (h.barycenter = f / p, h.weight = p), h;
}
function o(e, t, r) {
	for (var i; t.length && (i = n(t)).i <= r;) t.pop(), e.push(i.vs), r++;
	return r;
}
function s(e) {
	return function(t, n) {
		return t.barycenter < n.barycenter ? -1 : t.barycenter > n.barycenter ? 1 : e ? n.i - t.i : t.i - n.i;
	};
}
//#endregion
export { a as sort };
