import { reduce as x, forEach as o$1 } from "../../../min-dash/dist/index.esm.mjs";
import { getChildren as t, getVisual as n } from "../util/GraphicsUtil.mjs";
import { translate as i } from "../util/SvgTransformUtil.mjs";
import { clear as k } from "../../../min-dom/dist/index.esm.mjs";
import { create as M, classes as z, append as _, attr as N, remove as A } from "../../../tiny-svg/dist/index.esm.mjs";
import { isFrameElement as v } from "../util/Elements.mjs";
function o(t2, e) {
  this._eventBus = t2, this._elementRegistry = e;
}
o.$inject = ["eventBus", "elementRegistry"];
o.prototype._getChildrenContainer = function(t$1) {
  var e = this._elementRegistry.getGraphics(t$1), r;
  return t$1.parent ? (r = t(e), r || (r = M("g"), z(r).add("djs-children"), _(e.parentNode, r))) : r = e, r;
};
o.prototype._clear = function(t2) {
  var e = n(t2);
  return k(e), e;
};
o.prototype._createContainer = function(t2, e, r, i2) {
  var a = M("g");
  z(a).add("djs-group"), typeof r < "u" ? h(a, e, e.childNodes[r]) : _(e, a);
  var n2 = M("g");
  z(n2).add("djs-element"), z(n2).add("djs-" + t2), i2 && z(n2).add("djs-frame"), _(a, n2);
  var p = M("g");
  return z(p).add("djs-visual"), _(n2, p), n2;
};
o.prototype.create = function(t2, e, r) {
  var i2 = this._getChildrenContainer(e.parent);
  return this._createContainer(t2, i2, r, v(e));
};
o.prototype.updateContainments = function(t2) {
  var e = this, r = this._elementRegistry, i2;
  i2 = x(t2, function(a, n2) {
    return n2.parent && (a[n2.parent.id] = n2.parent), a;
  }, {}), o$1(i2, function(a) {
    var n2 = a.children;
    if (n2) {
      var p = e._getChildrenContainer(a);
      o$1(n2.slice().reverse(), function(l) {
        var v2 = r.getGraphics(l);
        h(v2.parentNode, p);
      });
    }
  });
};
o.prototype.drawShape = function(t2, e) {
  var r = this._eventBus;
  return r.fire("render.shape", { gfx: t2, element: e });
};
o.prototype.getShapePath = function(t2) {
  var e = this._eventBus;
  return e.fire("render.getShapePath", t2);
};
o.prototype.drawConnection = function(t2, e) {
  var r = this._eventBus;
  return r.fire("render.connection", { gfx: t2, element: e });
};
o.prototype.getConnectionPath = function(t2) {
  var e = this._eventBus;
  return e.fire("render.getConnectionPath", t2);
};
o.prototype.update = function(t2, e, r) {
  if (e.parent) {
    var i$1 = this._clear(r);
    if (t2 === "shape")
      this.drawShape(i$1, e), i(r, e.x, e.y);
    else if (t2 === "connection")
      this.drawConnection(i$1, e);
    else
      throw new Error("unknown type: " + t2);
    e.hidden ? N(r, "display", "none") : N(r, "display", "block");
  }
};
o.prototype.remove = function(t2) {
  var e = this._elementRegistry.getGraphics(t2);
  A(e.parentNode);
};
function h(t2, e, r) {
  var i2 = r || e.firstChild;
  t2 !== i2 && e.insertBefore(t2, i2);
}
export {
  o as default
};
