import { isPrimaryButton as o, hasPrimaryModifier as s, hasSecondaryModifier as c } from "../../util/Mouse.mjs";
import { isArray as p$1, find as _ } from "../../../../min-dash/dist/index.esm.mjs";
function S(r, n, l, f) {
  r.on("create.end", 500, function(t) {
    var e = t.context, i = e.canExecute, o2 = e.elements, c2 = e.hints || {}, a = c2.autoSelect;
    if (i) {
      if (a === false)
        return;
      p$1(a) ? n.select(a) : n.select(o2.filter(p));
    }
  }), r.on("connect.end", 500, function(t) {
    var e = t.context, i = e.connection;
    i && n.select(i);
  }), r.on("shape.move.end", 500, function(t) {
    var e = t.previousSelection || [], i = f.get(t.context.shape.id), o2 = _(e, function(c2) {
      return i.id === c2.id;
    });
    o2 || n.select(i);
  }), r.on("element.click", function(t) {
    if (o(t)) {
      var e = t.element;
      e === l.getRootElement() && (e = null);
      var i = n.isSelected(e), o$1 = n.get().length > 1, c$1 = s(t) || c(t);
      if (i && o$1)
        return c$1 ? n.deselect(e) : n.select(e);
      i ? n.deselect(e) : n.select(e, c$1);
    }
  });
}
S.$inject = [
  "eventBus",
  "selection",
  "canvas",
  "elementRegistry"
];
function p(r) {
  return !r.hidden;
}
export {
  S as default
};
