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