import browser from './browser.js';
import { makeKeyMap, makeKeyMapWithCommon } from '@modusoperandi/licit-doc-attrs-step';

// https://tinyurl.com/ybwf3wex

export function tooltip(keymap) {
  if (keymap) {
    var shortcut;
    if (browser.isMac()) {
      shortcut = keymap.mac.replace(/Cmd/i, '⌘').replace(/Shift/i, '⇧').replace(/Ctrl/i, '^').replace(/Alt/i, '⌥');
    } else {
      shortcut = keymap.windows;
    }
    return "".concat(keymap.description, " (").concat(shortcut, ")");
  }
  return null;
}
export function findShortcutByKeymap(keymap) {
  if (browser.isMac()) {
    return keymap.mac;
  }
  return keymap.windows;
}
export var KEY_BACK_DELETE = makeKeyMapWithCommon('', 'Backspace');
export var KEY_FORWARD_DELETE = makeKeyMapWithCommon('', 'Delete');
export var KEY_INSERT_HORIZONTAL_RULE = makeKeyMapWithCommon('Insert horizontal rule', 'Mod-Shift--');
export var KEY_INSERT_NEW_LINE_IN_BLOCKQUOTE = makeKeyMapWithCommon('Insert new line in blockquote', 'Shift-Enter');
export var KEY_REDO = makeKeyMapWithCommon('Redo', 'Mod-Shift-z');
export var KEY_SET_NORMAL_TEXT = makeKeyMap('Normal text', 'Ctrl-0', 'Cmd-Alt-0');
export var KEY_SHIFT_BACKSPACE = makeKeyMapWithCommon('Shift Backspace', 'Shift-Backspace');
export var KEY_SPLIT_CODEBLOCK = makeKeyMapWithCommon('Split code block', 'Enter');
export var KEY_SPLIT_LIST_ITEM = makeKeyMapWithCommon('Split list item', 'Enter');
export var KEY_TAB = makeKeyMapWithCommon('', 'Tab');
export var KEY_TAB_SHIFT = makeKeyMapWithCommon('', 'Shift-Tab');
export var KEY_TOGGLE_BLOCK_QUOTE = makeKeyMap('Block quote', 'Ctrl-7', 'Cmd-Alt-7');
export var KEY_TOGGLE_BOLD = makeKeyMapWithCommon('Toggle bold', 'Mod-b');
export var KEY_TOGGLE_BULLET_LIST = makeKeyMapWithCommon('Toggle bullet list', 'Mod-Shift-b');
export var KEY_TOGGLE_CODE_BLOCK = makeKeyMap('Code block', 'Ctrl-8', 'Cmd-Alt-8');
export var KEY_TOGGLE_HEADING_1 = makeKeyMap('Heading 1', 'Ctrl-1', 'Cmd-Alt-1');
export var KEY_TOGGLE_HEADING_2 = makeKeyMap('Heading 2', 'Ctrl-2', 'Cmd-Alt-2');
export var KEY_TOGGLE_HEADING_3 = makeKeyMap('Heading 3', 'Ctrl-3', 'Cmd-Alt-3');
export var KEY_TOGGLE_HEADING_4 = makeKeyMap('Heading 4', 'Ctrl-4', 'Cmd-Alt-4');
export var KEY_TOGGLE_HEADING_5 = makeKeyMap('Heading 5', 'Ctrl-5', 'Cmd-Alt-5');
export var KEY_TOGGLE_HEADING_6 = makeKeyMap('Heading 5', 'Ctrl-6', 'Cmd-Alt-6');
export var KEY_TOGGLE_ITALIC = makeKeyMapWithCommon('Toggle italic', 'Mod-i');
export var KEY_TOGGLE_MONOSPACE = makeKeyMapWithCommon('Toggle monospace', 'Mod-Shift-m');
export var KEY_TOGGLE_ORDERED_LIST = makeKeyMapWithCommon('Toggle ordered list', 'Mod-Shift-l');
export var KEY_TOGGLE_STRIKETHROUGH = makeKeyMapWithCommon('Toggle strikethrough', 'Mod-Shift-s');
export var KEY_TOGGLE_UNDERLINE = makeKeyMapWithCommon('Toggle underline', 'Mod-u');
export var KEY_UNDO = makeKeyMapWithCommon('Undo', 'Mod-z');
export var ALL_KEYS = [KEY_BACK_DELETE, KEY_FORWARD_DELETE, KEY_INSERT_HORIZONTAL_RULE, KEY_INSERT_NEW_LINE_IN_BLOCKQUOTE, KEY_SET_NORMAL_TEXT, KEY_SHIFT_BACKSPACE, KEY_SPLIT_LIST_ITEM, KEY_TAB_SHIFT, KEY_TAB, KEY_TOGGLE_BLOCK_QUOTE, KEY_TOGGLE_BOLD, KEY_TOGGLE_BULLET_LIST, KEY_TOGGLE_BULLET_LIST, KEY_TOGGLE_CODE_BLOCK, KEY_TOGGLE_HEADING_1, KEY_TOGGLE_HEADING_2, KEY_TOGGLE_HEADING_3, KEY_TOGGLE_HEADING_4, KEY_TOGGLE_HEADING_5, KEY_TOGGLE_HEADING_6, KEY_TOGGLE_ITALIC, KEY_TOGGLE_MONOSPACE, KEY_TOGGLE_ORDERED_LIST, KEY_TOGGLE_STRIKETHROUGH, KEY_TOGGLE_UNDERLINE, KEY_UNDO];
export function findKeymapByDescription(description) {
  var matches = ALL_KEYS.filter(function (keymap) {
    return keymap.description.toUpperCase() === description.toUpperCase();
  });
  return matches[0];
}
export function findShortcutByDescription(description) {
  var keymap = findKeymapByDescription(description);
  if (keymap) {
    return findShortcutByKeymap(keymap);
  }
  return null;
}