"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const graph = require("./src-graphlib-graph.cjs");
const forEach = require("../lodash-es/forEach.cjs");
const isUndefined = require("../lodash-es/isUndefined.cjs");
const uniqueId = require("../lodash-es/uniqueId.cjs");
function buildLayerGraph(g, rank, relationship) {
  var root = createRootNode(g), result = new graph.Graph({ compound: true }).setGraph({ root }).setDefaultNodeLabel(function(v) {
    return g.node(v);
  });
  forEach.default(g.nodes(), function(v) {
    var node = g.node(v), parent = g.parent(v);
    if (node.rank === rank || node.minRank <= rank && rank <= node.maxRank) {
      result.setNode(v);
      result.setParent(v, parent || root);
      forEach.default(g[relationship](v), function(e) {
        var u = e.v === v ? e.w : e.v, edge = result.edge(u, v), weight = !isUndefined.default(edge) ? edge.weight : 0;
        result.setEdge(u, v, { weight: g.edge(e).weight + weight });
      });
      if (Object.prototype.hasOwnProperty.call(node, "minRank")) {
        result.setNode(v, {
          borderLeft: node.borderLeft[rank],
          borderRight: node.borderRight[rank]
        });
      }
    }
  });
  return result;
}
function createRootNode(g) {
  var v;
  while (g.hasNode(v = uniqueId.default("_root"))) ;
  return v;
}
exports.buildLayerGraph = buildLayerGraph;
//# sourceMappingURL=src-dagre-order-build-layer-graph.cjs.map
