"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const keyCodes = require("../../../base/common/keyCodes.js");
const keybindings = require("../../../base/common/keybindings.js");
const baseResolvedKeybinding = require("./baseResolvedKeybinding.js");
const resolvedKeybindingItem = require("./resolvedKeybindingItem.js");
class USLayoutResolvedKeybinding extends baseResolvedKeybinding.BaseResolvedKeybinding {
  constructor(actual, os) {
    super(os, actual.parts);
  }
  _keyCodeToUILabel(keyCode) {
    if (this._os === 2) {
      switch (keyCode) {
        case 15:
          return "←";
        case 16:
          return "↑";
        case 17:
          return "→";
        case 18:
          return "↓";
      }
    }
    return keyCodes.KeyCodeUtils.toString(keyCode);
  }
  _getLabel(keybinding) {
    if (keybinding.isDuplicateModifierCase()) {
      return "";
    }
    return this._keyCodeToUILabel(keybinding.keyCode);
  }
  _getAriaLabel(keybinding) {
    if (keybinding.isDuplicateModifierCase()) {
      return "";
    }
    return keyCodes.KeyCodeUtils.toString(keybinding.keyCode);
  }
  _getElectronAccelerator(keybinding) {
    return keyCodes.KeyCodeUtils.toElectronAccelerator(keybinding.keyCode);
  }
  _getDispatchPart(keybinding) {
    return USLayoutResolvedKeybinding.getDispatchStr(keybinding);
  }
  static getDispatchStr(keybinding) {
    if (keybinding.isModifierKey()) {
      return null;
    }
    let result = "";
    if (keybinding.ctrlKey) {
      result += "ctrl+";
    }
    if (keybinding.shiftKey) {
      result += "shift+";
    }
    if (keybinding.altKey) {
      result += "alt+";
    }
    if (keybinding.metaKey) {
      result += "meta+";
    }
    result += keyCodes.KeyCodeUtils.toString(keybinding.keyCode);
    return result;
  }
  _getSingleModifierDispatchPart(keybinding) {
    if (keybinding.keyCode === 5 && !keybinding.shiftKey && !keybinding.altKey && !keybinding.metaKey) {
      return "ctrl";
    }
    if (keybinding.keyCode === 4 && !keybinding.ctrlKey && !keybinding.altKey && !keybinding.metaKey) {
      return "shift";
    }
    if (keybinding.keyCode === 6 && !keybinding.ctrlKey && !keybinding.shiftKey && !keybinding.metaKey) {
      return "alt";
    }
    if (keybinding.keyCode === 57 && !keybinding.ctrlKey && !keybinding.shiftKey && !keybinding.altKey) {
      return "meta";
    }
    return null;
  }
  /**
   * *NOTE*: Check return value for `KeyCode.Unknown`.
   */
  static _scanCodeToKeyCode(scanCode) {
    const immutableKeyCode = keyCodes.IMMUTABLE_CODE_TO_KEY_CODE[scanCode];
    if (immutableKeyCode !== -1) {
      return immutableKeyCode;
    }
    switch (scanCode) {
      case 10:
        return 31;
      case 11:
        return 32;
      case 12:
        return 33;
      case 13:
        return 34;
      case 14:
        return 35;
      case 15:
        return 36;
      case 16:
        return 37;
      case 17:
        return 38;
      case 18:
        return 39;
      case 19:
        return 40;
      case 20:
        return 41;
      case 21:
        return 42;
      case 22:
        return 43;
      case 23:
        return 44;
      case 24:
        return 45;
      case 25:
        return 46;
      case 26:
        return 47;
      case 27:
        return 48;
      case 28:
        return 49;
      case 29:
        return 50;
      case 30:
        return 51;
      case 31:
        return 52;
      case 32:
        return 53;
      case 33:
        return 54;
      case 34:
        return 55;
      case 35:
        return 56;
      case 36:
        return 22;
      case 37:
        return 23;
      case 38:
        return 24;
      case 39:
        return 25;
      case 40:
        return 26;
      case 41:
        return 27;
      case 42:
        return 28;
      case 43:
        return 29;
      case 44:
        return 30;
      case 45:
        return 21;
      case 51:
        return 83;
      case 52:
        return 81;
      case 53:
        return 87;
      case 54:
        return 89;
      case 55:
        return 88;
      case 56:
        return 0;
      case 57:
        return 80;
      case 58:
        return 90;
      case 59:
        return 86;
      case 60:
        return 82;
      case 61:
        return 84;
      case 62:
        return 85;
      case 106:
        return 92;
    }
    return 0;
  }
  static _resolveSimpleUserBinding(binding) {
    if (!binding) {
      return null;
    }
    if (binding instanceof keybindings.SimpleKeybinding) {
      return binding;
    }
    const keyCode = this._scanCodeToKeyCode(binding.scanCode);
    if (keyCode === 0) {
      return null;
    }
    return new keybindings.SimpleKeybinding(binding.ctrlKey, binding.shiftKey, binding.altKey, binding.metaKey, keyCode);
  }
  static resolveUserBinding(input, os) {
    const parts = resolvedKeybindingItem.removeElementsAfterNulls(input.map((keybinding) => this._resolveSimpleUserBinding(keybinding)));
    if (parts.length > 0) {
      return [new USLayoutResolvedKeybinding(new keybindings.ChordKeybinding(parts), os)];
    }
    return [];
  }
}
exports.USLayoutResolvedKeybinding = USLayoutResolvedKeybinding;
