import { isUndo, isRedo, isCopy, isPaste, isKey, isCmd } from "./KeyboardUtil.mjs";
var LOW_PRIORITY = 500;
function KeyboardBindings(eventBus, keyboard) {
  var self = this;
  eventBus.on("editorActions.init", LOW_PRIORITY, function(event) {
    var editorActions = event.editorActions;
    self.registerBindings(keyboard, editorActions);
  });
}
KeyboardBindings.$inject = [
  "eventBus",
  "keyboard"
];
KeyboardBindings.prototype.registerBindings = function(keyboard, editorActions) {
  function addListener(action, fn) {
    if (editorActions.isRegistered(action)) {
      keyboard.addListener(fn);
    }
  }
  addListener("undo", function(context) {
    var event = context.keyEvent;
    if (isUndo(event)) {
      editorActions.trigger("undo");
      return true;
    }
  });
  addListener("redo", function(context) {
    var event = context.keyEvent;
    if (isRedo(event)) {
      editorActions.trigger("redo");
      return true;
    }
  });
  addListener("copy", function(context) {
    var event = context.keyEvent;
    if (isCopy(event)) {
      editorActions.trigger("copy");
      return true;
    }
  });
  addListener("paste", function(context) {
    var event = context.keyEvent;
    if (isPaste(event)) {
      editorActions.trigger("paste");
      return true;
    }
  });
  addListener("stepZoom", function(context) {
    var event = context.keyEvent;
    if (isKey(["+", "Add", "="], event) && isCmd(event)) {
      editorActions.trigger("stepZoom", { value: 1 });
      return true;
    }
  });
  addListener("stepZoom", function(context) {
    var event = context.keyEvent;
    if (isKey(["-", "Subtract"], event) && isCmd(event)) {
      editorActions.trigger("stepZoom", { value: -1 });
      return true;
    }
  });
  addListener("zoom", function(context) {
    var event = context.keyEvent;
    if (isKey("0", event) && isCmd(event)) {
      editorActions.trigger("zoom", { value: 1 });
      return true;
    }
  });
  addListener("removeSelection", function(context) {
    var event = context.keyEvent;
    if (isKey(["Backspace", "Delete", "Del"], event)) {
      editorActions.trigger("removeSelection");
      return true;
    }
  });
};
export {
  KeyboardBindings as default
};
