import { isArray as p, forEach as o$1 } from "../../../../min-dash/dist/index.esm.mjs";
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();
  p(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 ? o$1(e, function(c) {
    t.indexOf(c) === -1 && t.push(c);
  }) : this._selectedElements = t = e.slice(), this._eventBus.fire("selection.changed", { oldSelection: i, newSelection: t });
};
export {
  o as default
};
