/**
 * @license MIT
 * author: Cube Dev Team
 * @cube-dev/ui-kit v0.108.1
 * Released under the MIT license.
 */

import { useMemo } from 'react';
import { useIsDarwin } from './useIsDarwin.js';
/* symbols that are identical on every OS */
const COMMON = {
    esc: 'Esc',
    escape: 'Esc',
    enter: '⏎',
    return: '⏎',
    space: '␣',
    backspace: '⌫',
    delete: '⌦',
    up: '↑',
    arrowup: '↑',
    down: '↓',
    arrowdown: '↓',
    left: '←',
    arrowleft: '←',
    right: '→',
    arrowright: '→',
};
/* modifiers for macOS / iOS */
const MAC = {
    mod: '⌘',
    meta: '⌘',
    cmd: '⌘',
    command: '⌘',
    ctrl: '⌃',
    control: '⌃',
    alt: '⌥',
    option: '⌥',
    shift: '⇧',
};
/* modifiers for Windows / Linux */
const PC = {
    mod: 'Ctrl',
    ctrl: 'Ctrl',
    control: 'Ctrl',
    meta: 'Win',
    win: 'Win',
    windows: 'Win',
    cmd: 'Win',
    command: 'Win',
    alt: '⎇',
    option: '⎇',
    shift: '⇧',
};
/**
 * useKeySymbols
 * -------------
 * Turns an author string such as
 *   "mod+k, ctrl+k"
 * into
 *   [["⌘", "K"], ["Ctrl", "K"]]
 */
export function useKeySymbols(combo) {
    const isDarwin = useIsDarwin(); // ⌘ by default during SSR
    const modifiers = isDarwin ? MAC : PC;
    return useMemo(() => {
        /** split on commas, trim each alternative */
        return combo
            .split(',')
            .map((raw) => raw.trim().toLowerCase())
            .filter(Boolean) // drop empty fragments
            .map((alternative) => alternative.split('+').map((part) => {
            const key = part.trim();
            return (modifiers[key] ?? // platform-specific modifier
                COMMON[key] ?? // shared glyphs
                part.toUpperCase() // plain key
            );
        }));
    }, [combo, modifiers]);
}

        