"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const index_esm = require("../../../../min-dash/dist/index.esm.js");
function o(e, n) {
  this._eventBus = e, this._canvas = n, this._selectedElements = [];
  var t = this;
  e.on(["shape.remove", "connection.remove"], function(i) {
    var s = i.element;
    t.deselect(s);
  }), e.on(["diagram.clear", "root.set"], function(i) {
    t.select(null);
  });
}
o.$inject = ["eventBus", "canvas"];
o.prototype.deselect = function(e) {
  var n = this._selectedElements, t = n.indexOf(e);
  if (t !== -1) {
    var i = n.slice();
    n.splice(t, 1), this._eventBus.fire("selection.changed", { oldSelection: i, newSelection: n });
  }
};
o.prototype.get = function() {
  return this._selectedElements;
};
o.prototype.isSelected = function(e) {
  return this._selectedElements.indexOf(e) !== -1;
};
o.prototype.select = function(e, n) {
  var t = this._selectedElements, i = t.slice();
  index_esm.isArray(e) || (e = e ? [e] : []);
  var s = this._canvas, l = s.getRootElement();
  e = e.filter(function(c) {
    var r = s.findRoot(c);
    return l === r;
  }), n ? index_esm.forEach(e, function(c) {
    t.indexOf(c) === -1 && t.push(c);
  }) : this._selectedElements = t = e.slice(), this._eventBus.fire("selection.changed", { oldSelection: i, newSelection: t });
};
exports.default = o;
