import { forEach as o, assign as q } from "../../../../min-dash/dist/index.esm.mjs";
import { clear as E, classes as z, create as M, attr as N, append as _ } from "../../../../tiny-svg/dist/index.esm.mjs";
import { getBBox as g } from "../../util/Elements.mjs";
var m = "hover", v = "selected", d = 6;
function S(t, i, r) {
  this._canvas = t;
  var l = this;
  this._multiSelectionBox = null;
  function c(e, a) {
    t.addMarker(e, a);
  }
  function o$1(e, a) {
    t.removeMarker(e, a);
  }
  i.on("element.hover", function(e) {
    c(e.element, m);
  }), i.on("element.out", function(e) {
    o$1(e.element, m);
  }), i.on("selection.changed", function(e) {
    function a(n) {
      o$1(n, v);
    }
    function g2(n) {
      c(n, v);
    }
    var f = e.oldSelection, u = e.newSelection;
    o(f, function(n) {
      u.indexOf(n) === -1 && a(n);
    }), o(u, function(n) {
      f.indexOf(n) === -1 && g2(n);
    }), l._updateSelectionOutline(u);
  }), i.on("element.changed", function(e) {
    r.isSelected(e.element) && l._updateSelectionOutline(r.get());
  });
}
S.$inject = [
  "canvas",
  "eventBus",
  "selection"
];
S.prototype._updateSelectionOutline = function(t) {
  var i = this._canvas.getLayer("selectionOutline");
  E(i);
  var r = t.length > 1, l = this._canvas.getContainer();
  if (z(l)[r ? "add" : "remove"]("djs-multi-select"), !!r) {
    var c = y(g(t)), o2 = M("rect");
    N(o2, q({
      rx: 3
    }, c)), z(o2).add("djs-selection-outline"), _(i, o2);
  }
};
function y(t) {
  return {
    x: t.x - d,
    y: t.y - d,
    width: t.width + d * 2,
    height: t.height + d * 2
  };
}
export {
  S as default
};
