import forEach_default from "../../../../lodash-es/forEach.js";
import isUndefined_default from "../../../../lodash-es/isUndefined.js";
import uniqueId_default from "../../../../lodash-es/uniqueId.js";
import { Graph } from "../../graphlib/graph.js";
import "../../graphlib/index.js";
function buildLayerGraph(n, i, o) {
	var s = createRootNode(n), c = new Graph({ compound: !0 }).setGraph({ root: s }).setDefaultNodeLabel(function(e) {
		return n.node(e);
	});
	return forEach_default(n.nodes(), function(r) {
		var a = n.node(r), l = n.parent(r);
		(a.rank === i || a.minRank <= i && i <= a.maxRank) && (c.setNode(r), c.setParent(r, l || s), forEach_default(n[o](r), function(e) {
			var i = e.v === r ? e.w : e.v, a = c.edge(i, r), o = isUndefined_default(a) ? 0 : a.weight;
			c.setEdge(i, r, { weight: n.edge(e).weight + o });
		}), Object.prototype.hasOwnProperty.call(a, "minRank") && c.setNode(r, {
			borderLeft: a.borderLeft[i],
			borderRight: a.borderRight[i]
		}));
	}), c;
}
function createRootNode(e) {
	for (var t; e.hasNode(t = uniqueId_default("_root")););
	return t;
}
export { buildLayerGraph };
