"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const errors = require("./errors.js");
function createKeybinding(keybinding, OS) {
  if (keybinding === 0) {
    return null;
  }
  const firstPart = (keybinding & 65535) >>> 0;
  const chordPart = (keybinding & 4294901760) >>> 16;
  if (chordPart !== 0) {
    return new ChordKeybinding([
      createSimpleKeybinding(firstPart, OS),
      createSimpleKeybinding(chordPart, OS)
    ]);
  }
  return new ChordKeybinding([createSimpleKeybinding(firstPart, OS)]);
}
function createSimpleKeybinding(keybinding, OS) {
  const ctrlCmd = keybinding & 2048 ? true : false;
  const winCtrl = keybinding & 256 ? true : false;
  const ctrlKey = OS === 2 ? winCtrl : ctrlCmd;
  const shiftKey = keybinding & 1024 ? true : false;
  const altKey = keybinding & 512 ? true : false;
  const metaKey = OS === 2 ? ctrlCmd : winCtrl;
  const keyCode = keybinding & 255;
  return new SimpleKeybinding(ctrlKey, shiftKey, altKey, metaKey, keyCode);
}
class SimpleKeybinding {
  constructor(ctrlKey, shiftKey, altKey, metaKey, keyCode) {
    this.ctrlKey = ctrlKey;
    this.shiftKey = shiftKey;
    this.altKey = altKey;
    this.metaKey = metaKey;
    this.keyCode = keyCode;
  }
  equals(other) {
    return this.ctrlKey === other.ctrlKey && this.shiftKey === other.shiftKey && this.altKey === other.altKey && this.metaKey === other.metaKey && this.keyCode === other.keyCode;
  }
  isModifierKey() {
    return this.keyCode === 0 || this.keyCode === 5 || this.keyCode === 57 || this.keyCode === 6 || this.keyCode === 4;
  }
  toChord() {
    return new ChordKeybinding([this]);
  }
  /**
   * Does this keybinding refer to the key code of a modifier and it also has the modifier flag?
   */
  isDuplicateModifierCase() {
    return this.ctrlKey && this.keyCode === 5 || this.shiftKey && this.keyCode === 4 || this.altKey && this.keyCode === 6 || this.metaKey && this.keyCode === 57;
  }
}
class ChordKeybinding {
  constructor(parts) {
    if (parts.length === 0) {
      throw errors.illegalArgument(`parts`);
    }
    this.parts = parts;
  }
}
class ResolvedKeybindingPart {
  constructor(ctrlKey, shiftKey, altKey, metaKey, kbLabel, kbAriaLabel) {
    this.ctrlKey = ctrlKey;
    this.shiftKey = shiftKey;
    this.altKey = altKey;
    this.metaKey = metaKey;
    this.keyLabel = kbLabel;
    this.keyAriaLabel = kbAriaLabel;
  }
}
class ResolvedKeybinding {
}
exports.ChordKeybinding = ChordKeybinding;
exports.ResolvedKeybinding = ResolvedKeybinding;
exports.ResolvedKeybindingPart = ResolvedKeybindingPart;
exports.SimpleKeybinding = SimpleKeybinding;
exports.createKeybinding = createKeybinding;
exports.createSimpleKeybinding = createSimpleKeybinding;
