import { Graph as a } from "../../graphlib/graph.js";
import { slack as f } from "./util.js";
import s from "../../../../../../lodash-es@4.17.22/node_modules/lodash-es/forEach.js";
import u from "../../../../../../lodash-es@4.17.22/node_modules/lodash-es/minBy.js";
function w(e) {
  var n = new a({ directed: !1 }), o = e.nodes()[0], t = e.nodeCount();
  n.setNode(o, {});
  for (var r, d; c(n, e) < t; )
    r = h(n, e), d = n.hasNode(r.v) ? f(e, r) : -f(e, r), m(n, e, d);
  return n;
}
function c(e, n) {
  function o(t) {
    s(n.nodeEdges(t), function(r) {
      var d = r.v, i = t === d ? r.w : d;
      !e.hasNode(i) && !f(n, r) && (e.setNode(i, {}), e.setEdge(t, i, {}), o(i));
    });
  }
  return s(e.nodes(), o), e.nodeCount();
}
function h(e, n) {
  return u(n.edges(), function(o) {
    if (e.hasNode(o.v) !== e.hasNode(o.w))
      return f(n, o);
  });
}
function m(e, n, o) {
  s(e.nodes(), function(t) {
    n.node(t).rank += o;
  });
}
export {
  w as feasibleTree
};
