import { greedyFAS as u } from "./greedy-fas.js";
import d from "../../../../../lodash-es@4.17.22/node_modules/lodash-es/forEach.js";
import i from "../../../../../lodash-es@4.17.22/node_modules/lodash-es/uniqueId.js";
function p(e) {
  var o = e.graph().acyclicer === "greedy" ? u(e, t(e)) : c(e);
  d(o, function(r) {
    var n = e.edge(r);
    e.removeEdge(r), n.forwardName = r.name, n.reversed = !0, e.setEdge(r.w, r.v, n, i("rev"));
  });
  function t(r) {
    return function(n) {
      return r.edge(n).weight;
    };
  }
}
function c(e) {
  var o = [], t = {}, r = {};
  function n(a) {
    Object.prototype.hasOwnProperty.call(r, a) || (r[a] = !0, t[a] = !0, d(e.outEdges(a), function(f) {
      Object.prototype.hasOwnProperty.call(t, f.w) ? o.push(f) : n(f.w);
    }), delete t[a]);
  }
  return d(e.nodes(), n), o;
}
function v(e) {
  d(e.edges(), function(o) {
    var t = e.edge(o);
    if (t.reversed) {
      e.removeEdge(o);
      var r = t.forwardName;
      delete t.reversed, delete t.forwardName, e.setEdge(o.w, o.v, t, r);
    }
  });
}
export {
  p as run,
  v as undo
};
