import '../core/String';  // For String#capitalise
import { isMac } from '../ua/UA';

const platformKeys = {
    ArrowUp: '↑',
    ArrowDown: '↓',
    ArrowRight: '→',
    ArrowLeft: '←',
    Alt: isMac ? '⌥' : 'Alt-',
    Cmd: isMac ? '⌘' : 'Ctrl-',
    Ctrl: isMac ? '⌃' : 'Ctrl-',
    Meta: isMac ? '⌘' : 'Meta-',
    Shift: isMac ? '⇧' : 'Shift-',
    Escape: 'Esc',
    Enter: isMac ? '↵' : 'Enter',
    Backspace: isMac ? '⌫' : 'Backspace',
};

/**
    Function: O.formatKeyForPlatform

    Parameters:
        shortcut - {String} The keyboard shorcut, in the same format as
                   taken by <O.GlobalKeyboardShortcuts#register>.

    Returns:
        {String} The shortcut formatted for display on the user's platform.
*/
export default function formatKeyForPlatform ( shortcut ) {
    return shortcut.split( '-' ).map(
        key => platformKeys[ key ] || key.capitalise()
    ).join( '' );
}

import '../core/String';  // For String#capitalise
import { isMac } from '../ua/UA';

const platformKeys = {
    ArrowUp: '↑',
    ArrowDown: '↓',
    ArrowRight: '→',
    ArrowLeft: '←',
    Alt: isMac ? '⌥' : 'Alt-',
    Cmd: isMac ? '⌘' : 'Ctrl-',
    Ctrl: isMac ? '⌃' : 'Ctrl-',
    Meta: isMac ? '⌘' : 'Meta-',
    Shift: isMac ? '⇧' : 'Shift-',
    Escape: 'Esc',
    Enter: isMac ? '↵' : 'Enter',
    Backspace: isMac ? '⌫' : 'Backspace',
    Delete: isMac ? '⌦' : 'Delete',
};

/**
    Function: O.formatKeyForPlatform

    Parameters:
        shortcut - {String} The keyboard shorcut, in the same format as
                   taken by <O.GlobalKeyboardShortcuts#register>.

    Returns:
        {String} The shortcut formatted for display on the user's platform.
*/
export default function formatKeyForPlatform ( shortcut ) {
    return shortcut.split( '-' ).map(
        key => platformKeys[ key ] || key.capitalise()
    ).join( '' );
}

Format `Delete` as “⌦” on macOS
Format `Delete` as “⌦” on macOS

“Delete” is the wrong label to show humans for keyboard shortcuts using
the `Delete` key on macOS, because Apple label their `Backspace` key
“Delete”, and they don’t tend to have a dedicated `Delete` key. On most
or all keyboards they sell now, Fn-Delete is what’s actually required to
get what the rest of the world calls Delete.

For the `Backspace` key code, Apple uses “Delete” in long form, and “⌫”,
U+232B ERASE TO THE LEFT, for the more common short form.

The `Delete` key code, Apple documentation calls “Forward Delete” in,
and I find “Fn-Delete” mentioned in one place (as something
keyboard-dependent, for which Control-D should be equivalent).
I can’t quickly find any keyboard shortcuts in menus that use `Delete`,
but a decade ago when they still sold keyboards with a `Delete` key,
they printed “delete ⌦” on that key, using U+2326 ERASE TO THE RIGHT, so
that’s clear and definite precedent.

“⌦” probably won’t be visually recognised by most (and may even be
confused for “⌫”), but it’s rare that we should want to format a
shortcut containing `Delete` anyway, and producing “Delete” is just
*wrong* and *definitely* confusing, since we don’t mean what the local
platform means by it—and we’ve had a report of such confusion from one
of our staff members in a place where we currently use `Delete` (where
we should actually be using `⌘⌫` on macOS).
