import { addDummyNode as f } from "./util.js";
import l from "../../../../../lodash-es@4.17.22/node_modules/lodash-es/forEach.js";
function b(e) {
  e.graph().dummyChains = [], l(e.edges(), function(d) {
    g(e, d);
  });
}
function g(e, d) {
  var a = d.v, i = e.node(a).rank, t = d.w, m = e.node(t).rank, u = d.name, n = e.edge(d), s = n.labelRank;
  if (m !== i + 1) {
    e.removeEdge(d);
    var r = void 0, h, o;
    for (o = 0, ++i; i < m; ++o, ++i)
      n.points = [], r = {
        width: 0,
        height: 0,
        edgeLabel: n,
        edgeObj: d,
        rank: i
      }, h = f(e, "edge", r, "_d"), i === s && (r.width = n.width, r.height = n.height, r.dummy = "edge-label", r.labelpos = n.labelpos), e.setEdge(a, h, { weight: n.weight }, u), o === 0 && e.graph().dummyChains.push(h), a = h;
    e.setEdge(a, t, { weight: n.weight }, u);
  }
}
function p(e) {
  l(e.graph().dummyChains, function(d) {
    var a = e.node(d), i = a.edgeLabel, t;
    for (e.setEdge(a.edgeObj, i); a.dummy; )
      t = e.successors(d)[0], e.removeNode(d), i.points.push({ x: a.x, y: a.y }), a.dummy === "edge-label" && (i.x = a.x, i.y = a.y, i.width = a.width, i.height = a.height), d = t, a = e.node(d);
  });
}
export {
  b as run,
  p as undo
};
