/**
 * Every keyboard shortcut the workspace answers to.
 *
 * One array, two consumers: useWorkspaceShortcuts binds them and
 * KeyboardShortcutsDialog lists them. That is deliberate — a shortcuts sheet
 * maintained separately from the handlers is a shortcuts sheet that lies, and
 * this one is reachable from the account menu where a merchant will believe it.
 *
 * `keys` is Kbd's format: `mod` renders as ⌘ on macOS and Ctrl elsewhere, and
 * `binding` below reads the same way.
 */

export type ShortcutId = 'toggleSidebar' | 'toggleLoyalyAi' | 'showShortcuts';

export interface Shortcut {
  /** Absent for the ones the browser already implements. */
  id?: ShortcutId;
  group: string;
  keys: string;
  label: string;
  /** The lowercase `event.key` this fires on, with mod held. */
  binding?: string;
}

export const WORKSPACE_SHORTCUTS: Shortcut[] = [
  {
    id: 'toggleSidebar',
    group: 'Navigation',
    keys: 'mod+b',
    label: 'Collapse or expand the sidebar',
    binding: 'b',
  },
  {
    id: 'toggleLoyalyAi',
    group: 'Navigation',
    keys: 'mod+j',
    label: 'Show or hide Loyaly AI',
    binding: 'j',
  },
  {
    id: 'showShortcuts',
    group: 'Help',
    keys: 'mod+/',
    label: 'Open this list',
    binding: '/',
  },
  // No binding: the native popover and dialog light-dismiss already do these,
  // and re-implementing them would only give the two a chance to disagree.
  {
    group: 'Overlays',
    keys: 'escape',
    label: 'Close the account menu, a panel or a dialog',
  },
  {
    group: 'Overlays',
    keys: 'tab',
    label: 'Move through the rows of an open panel',
  },
];

/** The groups, in the order they should be listed. */
export const SHORTCUT_GROUPS = [
  ...new Set(WORKSPACE_SHORTCUTS.map((s) => s.group)),
];
