import * as core from "input-core";

// NOTE: This is derived from rust's winit VirtualKeyCode as of 2023/07/07
export const Key = {
  /// The '1' key over the letters.
  Key1: 1,
  /// The '2' key over the letters.
  Key2: 2,
  /// The '3' key over the letters.
  Key3: 3,
  /// The '4' key over the letters.
  Key4: 4,
  /// The '5' key over the letters.
  Key5: 5,
  /// The '6' key over the letters.
  Key6: 6,
  /// The '7' key over the letters.
  Key7: 7,
  /// The '8' key over the letters.
  Key8: 8,
  /// The '9' key over the letters.
  Key9: 9,
  /// The '0' key over the 'O' and 'P' keys.
  Key0: 10,

  A: 11,
  B: 12,
  C: 13,
  D: 14,
  E: 15,
  F: 16,
  G: 17,
  H: 18,
  I: 19,
  J: 20,
  K: 21,
  L: 22,
  M: 23,
  N: 24,
  O: 25,
  P: 26,
  Q: 27,
  R: 28,
  S: 29,
  T: 30,
  U: 31,
  V: 32,
  W: 33,
  X: 34,
  Y: 35,
  Z: 36,

  /// The Escape key, next to F1.
  Escape: 37,

  F1: 38,
  F2: 39,
  F3: 40,
  F4: 41,
  F5: 42,
  F6: 43,
  F7: 44,
  F8: 45,
  F9: 46,
  F10: 47,
  F11: 48,
  F12: 49,
  F13: 50,
  F14: 51,
  F15: 52,
  F16: 53,
  F17: 54,
  F18: 55,
  F19: 56,
  F20: 57,
  F21: 58,
  F22: 59,
  F23: 60,
  F24: 61,

  /// Print Screen/SysRq.
  Snapshot: 62,
  /// Scroll Lock.
  Scroll: 63,
  /// Pause/Break key, next to Scroll lock.
  Pause: 64,

  /// `Insert`, next to Backspace.
  Insert: 65,
  Home: 66,
  Delete: 67,
  End: 68,
  PageDown: 69,
  PageUp: 70,

  Left: 71,
  Up: 72,
  Right: 73,
  Down: 74,

  /// The Backspace key, right over Enter.
  // TODO: rename
  Back: 75,
  /// The Enter key.
  Return: 76,
  /// The space bar.
  Space: 77,

  /// The "Compose" key on Linux.
  Compose: 78,

  Caret: 79,

  Numlock: 80,
  Numpad0: 81,
  Numpad1: 82,
  Numpad2: 83,
  Numpad3: 84,
  Numpad4: 85,
  Numpad5: 86,
  Numpad6: 87,
  Numpad7: 88,
  Numpad8: 89,
  Numpad9: 90,
  NumpadAdd: 91,
  NumpadDivide: 92,
  NumpadDecimal: 93,
  NumpadComma: 94,
  NumpadEnter: 95,
  NumpadEquals: 96,
  NumpadMultiply: 97,
  NumpadSubtract: 98,

  AbntC1: 99,
  AbntC2: 100,
  Apostrophe: 101,
  Apps: 102,
  Asterisk: 103,
  At: 104,
  Ax: 105,
  Backslash: 106,
  Calculator: 107,
  Capital: 108,
  Colon: 109,
  Comma: 110,
  Convert: 111,
  Equals: 112,
  Grave: 113,
  Kana: 114,
  Kanji: 115,
  LAlt: 116,
  LBracket: 117,
  LControl: 118,
  LShift: 119,
  LWin: 120,
  Mail: 121,
  MediaSelect: 122,
  MediaStop: 123,
  Minus: 124,
  Mute: 125,
  MyComputer: 126,
  // also called "Next"
  NavigateForward: 127,
  // also called "Prior"
  NavigateBackward: 128,
  NextTrack: 129,
  NoConvert: 130,
  OEM102: 131,
  Period: 132,
  PlayPause: 133,
  Plus: 134,
  Power: 135,
  PrevTrack: 136,
  RAlt: 137,
  RBracket: 138,
  RControl: 139,
  RShift: 140,
  RWin: 141,
  Semicolon: 142,
  Slash: 143,
  Sleep: 144,
  Stop: 145,
  Sysrq: 146,
  Tab: 147,
  Underline: 148,
  Unlabeled: 149,
  VolumeDown: 150,
  VolumeUp: 151,
  Wake: 152,
  WebBack: 153,
  WebFavorites: 154,
  WebForward: 155,
  WebHome: 156,
  WebRefresh: 157,
  WebSearch: 158,
  WebStop: 159,
  Yen: 160,
  Copy: 161,
  Paste: 162,
  Cut: 163,
} as const;

// NOTE: This must match the definition in input.rs.
export const Button = {
  Up: core.BUTTON_UP,
  Down: core.BUTTON_DOWN,
  Left: core.BUTTON_LEFT,
  Right: core.BUTTON_RIGHT,
} as const;
type Button = (typeof Button)[keyof typeof Button];

export function btn(b: Button): boolean {
  return core.btn(b);
}
