import { Graph as c } from "../graphlib/graph.js";
import d from "../../../../../lodash-es@4.17.22/node_modules/lodash-es/forEach.js";
import p from "../../../../../lodash-es@4.17.22/node_modules/lodash-es/min.js";
import s from "../../../../../lodash-es@4.17.22/node_modules/lodash-es/map.js";
import h from "../../../../../lodash-es@4.17.22/node_modules/lodash-es/isUndefined.js";
import l from "../../../../../lodash-es@4.17.22/node_modules/lodash-es/has.js";
import v from "../../../../../lodash-es@4.17.22/node_modules/lodash-es/uniqueId.js";
import k from "../../../../../lodash-es@4.17.22/node_modules/lodash-es/range.js";
import w from "../../../../../lodash-es@4.17.22/node_modules/lodash-es/max.js";
function y(n, e, r, o) {
  var i;
  do
    i = v(o);
  while (n.hasNode(i));
  return r.dummy = e, n.setNode(i, r), i;
}
function q(n) {
  var e = new c().setGraph(n.graph());
  return d(n.nodes(), function(r) {
    e.setNode(r, n.node(r));
  }), d(n.edges(), function(r) {
    var o = e.edge(r.v, r.w) || { weight: 0, minlen: 1 }, i = n.edge(r);
    e.setEdge(r.v, r.w, {
      weight: o.weight + i.weight,
      minlen: Math.max(o.minlen, i.minlen)
    });
  }), e;
}
function z(n) {
  var e = new c({ multigraph: n.isMultigraph() }).setGraph(n.graph());
  return d(n.nodes(), function(r) {
    n.children(r).length || e.setNode(r, n.node(r));
  }), d(n.edges(), function(r) {
    e.setEdge(r, n.edge(r));
  }), e;
}
function B(n, e) {
  var r = n.x, o = n.y, i = e.x - r, t = e.y - o, a = n.width / 2, f = n.height / 2;
  if (!i && !t)
    throw new Error("Not possible to find intersection inside of the rectangle");
  var u, m;
  return Math.abs(t) * a > Math.abs(i) * f ? (t < 0 && (f = -f), u = f * i / t, m = f) : (i < 0 && (a = -a), u = a, m = a * t / i), { x: r + u, y: o + m };
}
function C(n) {
  var e = s(k(x(n) + 1), function() {
    return [];
  });
  return d(n.nodes(), function(r) {
    var o = n.node(r), i = o.rank;
    h(i) || (e[i][o.order] = r);
  }), e;
}
function D(n) {
  var e = p(
    s(n.nodes(), function(r) {
      return n.node(r).rank;
    })
  );
  d(n.nodes(), function(r) {
    var o = n.node(r);
    l(o, "rank") && (o.rank -= e);
  });
}
function I(n) {
  var e = p(
    s(n.nodes(), function(t) {
      return n.node(t).rank;
    })
  ), r = [];
  d(n.nodes(), function(t) {
    var a = n.node(t).rank - e;
    r[a] || (r[a] = []), r[a].push(t);
  });
  var o = 0, i = n.graph().nodeRankFactor;
  d(r, function(t, a) {
    h(t) && a % i !== 0 ? --o : o && d(t, function(f) {
      n.node(f).rank += o;
    });
  });
}
function U(n, e, r, o) {
  var i = {
    width: 0,
    height: 0
  };
  return arguments.length >= 4 && (i.rank = r, i.order = o), y(n, "border", i, e);
}
function x(n) {
  return w(
    s(n.nodes(), function(e) {
      var r = n.node(e).rank;
      if (!h(r))
        return r;
    })
  );
}
function $(n, e) {
  var r = { lhs: [], rhs: [] };
  return d(n, function(o) {
    e(o) ? r.lhs.push(o) : r.rhs.push(o);
  }), r;
}
function j(n, e) {
  return e();
}
export {
  U as addBorderNode,
  y as addDummyNode,
  z as asNonCompoundGraph,
  C as buildLayerMatrix,
  B as intersectRect,
  x as maxRank,
  D as normalizeRanks,
  j as notime,
  $ as partition,
  I as removeEmptyRanks,
  q as simplify
};
