/**
 * Utilities for formatting keybinding hints in the UI.
 */
import { getKeybindings } from "@earendil-works/pi-tui";
import { theme } from "../theme/theme.js";
const MODIFIER_LABELS = {
    ctrl: "ctrl",
    control: "ctrl",
    cmd: "cmd",
    command: "cmd",
    shift: "shift",
    alt: "alt",
    option: "alt",
    meta: "meta",
};
const SPECIAL_KEY_LABELS = {
    enter: "enter",
    return: "enter",
    esc: "esc",
    escape: "esc",
    space: "space",
    tab: "tab",
    backspace: "backspace",
    delete: "delete",
    del: "delete",
    up: "up",
    down: "down",
    left: "left",
    right: "right",
    home: "home",
    end: "end",
    pageup: "pageup",
    pagedown: "pagedown",
};
function formatKeyPart(part, _options) {
    const lower = part.toLowerCase();
    const modifier = MODIFIER_LABELS[lower];
    if (modifier)
        return modifier;
    const special = SPECIAL_KEY_LABELS[lower];
    if (special)
        return special;
    if (/^f\d+$/i.test(part))
        return lower;
    if (/^[a-z]$/i.test(part))
        return lower;
    return part.toLowerCase();
}
export function formatKeyText(key, options = {}) {
    return key
        .split("/")
        .map((k) => k
        .split("+")
        .map((part) => formatKeyPart(part, options))
        .join("+"))
        .join("/");
}
function formatKeys(keys, options = {}) {
    if (keys.length === 0)
        return "";
    return formatKeyText(keys.join("/"), options);
}
export function keyText(keybinding) {
    return formatKeys(getKeybindings().getKeys(keybinding));
}
export function keyDisplayText(keybinding) {
    return formatKeys(getKeybindings().getKeys(keybinding), { capitalize: true });
}
function formatHintLabel(description) {
    return description;
}
export function keyHint(keybinding, description) {
    return theme.fg("dim", keyText(keybinding)) + theme.fg("muted", ` ${formatHintLabel(description)}`);
}
export function rawKeyHint(key, description) {
    return theme.fg("dim", formatKeyText(key)) + theme.fg("muted", ` ${formatHintLabel(description)}`);
}
//# sourceMappingURL=keybinding-hints.js.map