import e from "../../../../lodash-es/filter.js";
import t from "../../../../lodash-es/flatten.js";
import n from "../../../../lodash-es/forEach.js";
import r from "../../../../lodash-es/isUndefined.js";
import { barycenter as i } from "./barycenter.js";
import { resolveConflicts as a } from "./resolve-conflicts.js";
import { sort as o } from "./sort.js";
//#region ../../node_modules/dagre-d3-es/src/dagre/order/sort-subgraph.js
function s(r, u, d, f) {
	var p = r.children(u), m = r.node(u), h = m ? m.borderLeft : void 0, g = m ? m.borderRight : void 0, _ = {};
	h && (p = e(p, function(e) {
		return e !== h && e !== g;
	}));
	var v = i(r, p);
	n(v, function(e) {
		if (r.children(e.v).length) {
			var t = s(r, e.v, d, f);
			_[e.v] = t, Object.prototype.hasOwnProperty.call(t, "barycenter") && l(e, t);
		}
	});
	var y = a(v, d);
	c(y, _);
	var b = o(y, f);
	if (h && (b.vs = t([
		h,
		b.vs,
		g
	]), r.predecessors(h).length)) {
		var x = r.node(r.predecessors(h)[0]), S = r.node(r.predecessors(g)[0]);
		Object.prototype.hasOwnProperty.call(b, "barycenter") || (b.barycenter = 0, b.weight = 0), b.barycenter = (b.barycenter * b.weight + x.order + S.order) / (b.weight + 2), b.weight += 2;
	}
	return b;
}
function c(e, r) {
	n(e, function(e) {
		e.vs = t(e.vs.map(function(e) {
			return r[e] ? r[e].vs : e;
		}));
	});
}
function l(e, t) {
	r(e.barycenter) ? (e.barycenter = t.barycenter, e.weight = t.weight) : (e.barycenter = (e.barycenter * e.weight + t.barycenter * t.weight) / (e.weight + t.weight), e.weight += t.weight);
}
//#endregion
export { s as sortSubgraph };
