import e from "../../../lodash-es/isFunction.js";
import t from "../../../lodash-es/constant.js";
import n from "../../../lodash-es/isEmpty.js";
import r from "../../../lodash-es/keys.js";
import i from "../../../lodash-es/filter.js";
import a from "../../../lodash-es/forEach.js";
import o from "../../../lodash-es/reduce.js";
import s from "../../../lodash-es/values.js";
import c from "../../../lodash-es/isUndefined.js";
import l from "../../../lodash-es/union.js";
//#region ../../node_modules/dagre-d3-es/src/graphlib/graph.js
var u = "\0", d = "\0", f = "", p = class {
	constructor(e = {}) {
		this._isDirected = Object.prototype.hasOwnProperty.call(e, "directed") ? e.directed : !0, this._isMultigraph = Object.prototype.hasOwnProperty.call(e, "multigraph") ? e.multigraph : !1, this._isCompound = Object.prototype.hasOwnProperty.call(e, "compound") ? e.compound : !1, this._label = void 0, this._defaultNodeLabelFn = t(void 0), this._defaultEdgeLabelFn = t(void 0), this._nodes = {}, this._isCompound && (this._parent = {}, this._children = {}, this._children[d] = {}), this._in = {}, this._preds = {}, this._out = {}, this._sucs = {}, this._edgeObjs = {}, this._edgeLabels = {};
	}
	isDirected() {
		return this._isDirected;
	}
	isMultigraph() {
		return this._isMultigraph;
	}
	isCompound() {
		return this._isCompound;
	}
	setGraph(e) {
		return this._label = e, this;
	}
	graph() {
		return this._label;
	}
	setDefaultNodeLabel(n) {
		return e(n) || (n = t(n)), this._defaultNodeLabelFn = n, this;
	}
	nodeCount() {
		return this._nodeCount;
	}
	nodes() {
		return r(this._nodes);
	}
	sources() {
		var e = this;
		return i(this.nodes(), function(t) {
			return n(e._in[t]);
		});
	}
	sinks() {
		var e = this;
		return i(this.nodes(), function(t) {
			return n(e._out[t]);
		});
	}
	setNodes(e, t) {
		var n = arguments, r = this;
		return a(e, function(e) {
			n.length > 1 ? r.setNode(e, t) : r.setNode(e);
		}), this;
	}
	setNode(e, t) {
		return Object.prototype.hasOwnProperty.call(this._nodes, e) ? (arguments.length > 1 && (this._nodes[e] = t), this) : (this._nodes[e] = arguments.length > 1 ? t : this._defaultNodeLabelFn(e), this._isCompound && (this._parent[e] = d, this._children[e] = {}, this._children[d][e] = !0), this._in[e] = {}, this._preds[e] = {}, this._out[e] = {}, this._sucs[e] = {}, ++this._nodeCount, this);
	}
	node(e) {
		return this._nodes[e];
	}
	hasNode(e) {
		return Object.prototype.hasOwnProperty.call(this._nodes, e);
	}
	removeNode(e) {
		if (Object.prototype.hasOwnProperty.call(this._nodes, e)) {
			var t = (e) => this.removeEdge(this._edgeObjs[e]);
			delete this._nodes[e], this._isCompound && (this._removeFromParentsChildList(e), delete this._parent[e], a(this.children(e), (e) => {
				this.setParent(e);
			}), delete this._children[e]), a(r(this._in[e]), t), delete this._in[e], delete this._preds[e], a(r(this._out[e]), t), delete this._out[e], delete this._sucs[e], --this._nodeCount;
		}
		return this;
	}
	setParent(e, t) {
		if (!this._isCompound) throw Error("Cannot set parent in a non-compound graph");
		if (c(t)) t = d;
		else {
			t += "";
			for (var n = t; !c(n); n = this.parent(n)) if (n === e) throw Error("Setting " + t + " as parent of " + e + " would create a cycle");
			this.setNode(t);
		}
		return this.setNode(e), this._removeFromParentsChildList(e), this._parent[e] = t, this._children[t][e] = !0, this;
	}
	_removeFromParentsChildList(e) {
		delete this._children[this._parent[e]][e];
	}
	parent(e) {
		if (this._isCompound) {
			var t = this._parent[e];
			if (t !== d) return t;
		}
	}
	children(e) {
		if (c(e) && (e = d), this._isCompound) {
			var t = this._children[e];
			if (t) return r(t);
		} else if (e === d) return this.nodes();
		else if (this.hasNode(e)) return [];
	}
	predecessors(e) {
		var t = this._preds[e];
		if (t) return r(t);
	}
	successors(e) {
		var t = this._sucs[e];
		if (t) return r(t);
	}
	neighbors(e) {
		var t = this.predecessors(e);
		if (t) return l(t, this.successors(e));
	}
	isLeaf(e) {
		return (this.isDirected() ? this.successors(e) : this.neighbors(e)).length === 0;
	}
	filterNodes(e) {
		var t = new this.constructor({
			directed: this._isDirected,
			multigraph: this._isMultigraph,
			compound: this._isCompound
		});
		t.setGraph(this.graph());
		var n = this;
		a(this._nodes, function(n, r) {
			e(r) && t.setNode(r, n);
		}), a(this._edgeObjs, function(e) {
			t.hasNode(e.v) && t.hasNode(e.w) && t.setEdge(e, n.edge(e));
		});
		var r = {};
		function i(e) {
			var a = n.parent(e);
			return a === void 0 || t.hasNode(a) ? (r[e] = a, a) : a in r ? r[a] : i(a);
		}
		return this._isCompound && a(t.nodes(), function(e) {
			t.setParent(e, i(e));
		}), t;
	}
	setDefaultEdgeLabel(n) {
		return e(n) || (n = t(n)), this._defaultEdgeLabelFn = n, this;
	}
	edgeCount() {
		return this._edgeCount;
	}
	edges() {
		return s(this._edgeObjs);
	}
	setPath(e, t) {
		var n = this, r = arguments;
		return o(e, function(e, i) {
			return r.length > 1 ? n.setEdge(e, i, t) : n.setEdge(e, i), i;
		}), this;
	}
	setEdge() {
		var e, t, n, r, i = !1, a = arguments[0];
		typeof a == "object" && a && "v" in a ? (e = a.v, t = a.w, n = a.name, arguments.length === 2 && (r = arguments[1], i = !0)) : (e = a, t = arguments[1], n = arguments[3], arguments.length > 2 && (r = arguments[2], i = !0)), e = "" + e, t = "" + t, c(n) || (n = "" + n);
		var o = g(this._isDirected, e, t, n);
		if (Object.prototype.hasOwnProperty.call(this._edgeLabels, o)) return i && (this._edgeLabels[o] = r), this;
		if (!c(n) && !this._isMultigraph) throw Error("Cannot set a named edge when isMultigraph = false");
		this.setNode(e), this.setNode(t), this._edgeLabels[o] = i ? r : this._defaultEdgeLabelFn(e, t, n);
		var s = _(this._isDirected, e, t, n);
		return e = s.v, t = s.w, Object.freeze(s), this._edgeObjs[o] = s, m(this._preds[t], e), m(this._sucs[e], t), this._in[t][o] = s, this._out[e][o] = s, this._edgeCount++, this;
	}
	edge(e, t, n) {
		var r = arguments.length === 1 ? v(this._isDirected, arguments[0]) : g(this._isDirected, e, t, n);
		return this._edgeLabels[r];
	}
	hasEdge(e, t, n) {
		var r = arguments.length === 1 ? v(this._isDirected, arguments[0]) : g(this._isDirected, e, t, n);
		return Object.prototype.hasOwnProperty.call(this._edgeLabels, r);
	}
	removeEdge(e, t, n) {
		var r = arguments.length === 1 ? v(this._isDirected, arguments[0]) : g(this._isDirected, e, t, n), i = this._edgeObjs[r];
		return i && (e = i.v, t = i.w, delete this._edgeLabels[r], delete this._edgeObjs[r], h(this._preds[t], e), h(this._sucs[e], t), delete this._in[t][r], delete this._out[e][r], this._edgeCount--), this;
	}
	inEdges(e, t) {
		var n = this._in[e];
		if (n) {
			var r = s(n);
			return t ? i(r, function(e) {
				return e.v === t;
			}) : r;
		}
	}
	outEdges(e, t) {
		var n = this._out[e];
		if (n) {
			var r = s(n);
			return t ? i(r, function(e) {
				return e.w === t;
			}) : r;
		}
	}
	nodeEdges(e, t) {
		var n = this.inEdges(e, t);
		if (n) return n.concat(this.outEdges(e, t));
	}
};
p.prototype._nodeCount = 0, p.prototype._edgeCount = 0;
function m(e, t) {
	e[t] ? e[t]++ : e[t] = 1;
}
function h(e, t) {
	--e[t] || delete e[t];
}
function g(e, t, n, r) {
	var i = "" + t, a = "" + n;
	if (!e && i > a) {
		var o = i;
		i = a, a = o;
	}
	return i + f + a + f + (c(r) ? u : r);
}
function _(e, t, n, r) {
	var i = "" + t, a = "" + n;
	if (!e && i > a) {
		var o = i;
		i = a, a = o;
	}
	var s = {
		v: i,
		w: a
	};
	return r && (s.name = r), s;
}
function v(e, t) {
	return g(e, t.v, t.w, t.name);
}
//#endregion
export { p as Graph };
