"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const index_esm = require("../../../tiny-svg/dist/index.esm.js");
var s = "data-element-id";
function n(t) {
  this._elements = {}, this._eventBus = t;
}
n.$inject = ["eventBus"];
n.prototype.add = function(t, e, i) {
  var r = t.id;
  this._validateId(r), index_esm.attr(e, s, r), i && index_esm.attr(i, s, r), this._elements[r] = { element: t, gfx: e, secondaryGfx: i };
};
n.prototype.remove = function(t) {
  var e = this._elements, i = t.id || t, r = i && e[i];
  r && (index_esm.attr(r.gfx, s, ""), r.secondaryGfx && index_esm.attr(r.secondaryGfx, s, ""), delete e[i]);
};
n.prototype.updateId = function(t, e) {
  this._validateId(e), typeof t == "string" && (t = this.get(t)), this._eventBus.fire("element.updateId", {
    element: t,
    newId: e
  });
  var i = this.getGraphics(t), r = this.getGraphics(t, true);
  this.remove(t), t.id = e, this.add(t, i, r);
};
n.prototype.updateGraphics = function(t, e, i) {
  var r = t.id || t, o = this._elements[r];
  return i ? o.secondaryGfx = e : o.gfx = e, e && index_esm.attr(e, s, r), e;
};
n.prototype.get = function(t) {
  var e;
  typeof t == "string" ? e = t : e = t && index_esm.attr(t, s);
  var i = this._elements[e];
  return i && i.element;
};
n.prototype.filter = function(t) {
  var e = [];
  return this.forEach(function(i, r) {
    t(i, r) && e.push(i);
  }), e;
};
n.prototype.find = function(t) {
  for (var e = this._elements, i = Object.keys(e), r = 0; r < i.length; r++) {
    var o = i[r], f = e[o], d = f.element, p = f.gfx;
    if (t(d, p))
      return d;
  }
};
n.prototype.getAll = function() {
  return this.filter(function(t) {
    return t;
  });
};
n.prototype.forEach = function(t) {
  var e = this._elements;
  Object.keys(e).forEach(function(i) {
    var r = e[i], o = r.element, f = r.gfx;
    return t(o, f);
  });
};
n.prototype.getGraphics = function(t, e) {
  var i = t.id || t, r = this._elements[i];
  return r && (e ? r.secondaryGfx : r.gfx);
};
n.prototype._validateId = function(t) {
  if (!t)
    throw new Error("element must have an id");
  if (this._elements[t])
    throw new Error("element with id " + t + " already added");
};
exports.default = n;
