"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const index_esm = require("../../../../min-dash/dist/index.esm.js");
const index_esm$1 = require("../../../../tiny-svg/dist/index.esm.js");
const Elements = require("../../util/Elements.js");
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(e, a) {
    t.removeMarker(e, a);
  }
  i.on("element.hover", function(e) {
    c(e.element, m);
  }), i.on("element.out", function(e) {
    o(e.element, m);
  }), i.on("selection.changed", function(e) {
    function a(n) {
      o(n, v);
    }
    function g(n) {
      c(n, v);
    }
    var f = e.oldSelection, u = e.newSelection;
    index_esm.forEach(f, function(n) {
      u.indexOf(n) === -1 && a(n);
    }), index_esm.forEach(u, function(n) {
      f.indexOf(n) === -1 && g(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");
  index_esm$1.clear(i);
  var r = t.length > 1, l = this._canvas.getContainer();
  if (index_esm$1.classes(l)[r ? "add" : "remove"]("djs-multi-select"), !!r) {
    var c = y(Elements.getBBox(t)), o = index_esm$1.create("rect");
    index_esm$1.attr(o, index_esm.assign({
      rx: 3
    }, c)), index_esm$1.classes(o).add("djs-selection-outline"), index_esm$1.append(i, o);
  }
};
function y(t) {
  return {
    x: t.x - d,
    y: t.y - d,
    width: t.width + d * 2,
    height: t.height + d * 2
  };
}
exports.default = S;
