"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const index_esm$2 = require("../../../min-dash/dist/index.esm.js");
const GraphicsUtil = require("../util/GraphicsUtil.js");
const SvgTransformUtil = require("../util/SvgTransformUtil.js");
const index_esm$1 = require("../../../min-dom/dist/index.esm.js");
const index_esm = require("../../../tiny-svg/dist/index.esm.js");
const Elements = require("../util/Elements.js");
function o(t, e) {
  this._eventBus = t, this._elementRegistry = e;
}
o.$inject = ["eventBus", "elementRegistry"];
o.prototype._getChildrenContainer = function(t) {
  var e = this._elementRegistry.getGraphics(t), r;
  return t.parent ? (r = GraphicsUtil.getChildren(e), r || (r = index_esm.create("g"), index_esm.classes(r).add("djs-children"), index_esm.append(e.parentNode, r))) : r = e, r;
};
o.prototype._clear = function(t) {
  var e = GraphicsUtil.getVisual(t);
  return index_esm$1.clear(e), e;
};
o.prototype._createContainer = function(t, e, r, i) {
  var a = index_esm.create("g");
  index_esm.classes(a).add("djs-group"), typeof r < "u" ? h(a, e, e.childNodes[r]) : index_esm.append(e, a);
  var n = index_esm.create("g");
  index_esm.classes(n).add("djs-element"), index_esm.classes(n).add("djs-" + t), i && index_esm.classes(n).add("djs-frame"), index_esm.append(a, n);
  var p = index_esm.create("g");
  return index_esm.classes(p).add("djs-visual"), index_esm.append(n, p), n;
};
o.prototype.create = function(t, e, r) {
  var i = this._getChildrenContainer(e.parent);
  return this._createContainer(t, i, r, Elements.isFrameElement(e));
};
o.prototype.updateContainments = function(t) {
  var e = this, r = this._elementRegistry, i;
  i = index_esm$2.reduce(t, function(a, n) {
    return n.parent && (a[n.parent.id] = n.parent), a;
  }, {}), index_esm$2.forEach(i, function(a) {
    var n = a.children;
    if (n) {
      var p = e._getChildrenContainer(a);
      index_esm$2.forEach(n.slice().reverse(), function(l) {
        var v = r.getGraphics(l);
        h(v.parentNode, p);
      });
    }
  });
};
o.prototype.drawShape = function(t, e) {
  var r = this._eventBus;
  return r.fire("render.shape", { gfx: t, element: e });
};
o.prototype.getShapePath = function(t) {
  var e = this._eventBus;
  return e.fire("render.getShapePath", t);
};
o.prototype.drawConnection = function(t, e) {
  var r = this._eventBus;
  return r.fire("render.connection", { gfx: t, element: e });
};
o.prototype.getConnectionPath = function(t) {
  var e = this._eventBus;
  return e.fire("render.getConnectionPath", t);
};
o.prototype.update = function(t, e, r) {
  if (e.parent) {
    var i = this._clear(r);
    if (t === "shape")
      this.drawShape(i, e), SvgTransformUtil.translate(r, e.x, e.y);
    else if (t === "connection")
      this.drawConnection(i, e);
    else
      throw new Error("unknown type: " + t);
    e.hidden ? index_esm.attr(r, "display", "none") : index_esm.attr(r, "display", "block");
  }
};
o.prototype.remove = function(t) {
  var e = this._elementRegistry.getGraphics(t);
  index_esm.remove(e.parentNode);
};
function h(t, e, r) {
  var i = r || e.firstChild;
  t !== i && e.insertBefore(t, i);
}
exports.default = o;
