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