"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const greedyFas = require("./src-dagre-greedy-fas.cjs");
const forEach = require("../lodash-es/forEach.cjs");
const uniqueId = require("../lodash-es/uniqueId.cjs");
function run(g) {
  var fas = g.graph().acyclicer === "greedy" ? greedyFas.greedyFAS(g, weightFn(g)) : dfsFAS(g);
  forEach.default(fas, function(e) {
    var label = g.edge(e);
    g.removeEdge(e);
    label.forwardName = e.name;
    label.reversed = true;
    g.setEdge(e.w, e.v, label, uniqueId.default("rev"));
  });
  function weightFn(g2) {
    return function(e) {
      return g2.edge(e).weight;
    };
  }
}
function dfsFAS(g) {
  var fas = [];
  var stack = {};
  var visited = {};
  function dfs(v) {
    if (Object.prototype.hasOwnProperty.call(visited, v)) {
      return;
    }
    visited[v] = true;
    stack[v] = true;
    forEach.default(g.outEdges(v), function(e) {
      if (Object.prototype.hasOwnProperty.call(stack, e.w)) {
        fas.push(e);
      } else {
        dfs(e.w);
      }
    });
    delete stack[v];
  }
  forEach.default(g.nodes(), dfs);
  return fas;
}
function undo(g) {
  forEach.default(g.edges(), function(e) {
    var label = g.edge(e);
    if (label.reversed) {
      g.removeEdge(e);
      var forwardName = label.forwardName;
      delete label.reversed;
      delete label.forwardName;
      g.setEdge(e.w, e.v, label, forwardName);
    }
  });
}
exports.run = run;
exports.undo = undo;
//# sourceMappingURL=src-dagre-acyclic.cjs.map
