import { parseShortcut } from "./parser.js";
import { loadKeybindingsSync } from "./loadUserBindings.js";
import { getBindingDisplayText } from "./resolver.js";
export function formatKeystroke(key) {
    const parts = [
        key.ctrl ? "Ctrl" : "",
        key.alt ? "Alt" : "",
        key.shift ? "Shift" : "",
        key.meta ? "Meta" : "",
        displayKey(key.key ?? ""),
    ].filter(Boolean);
    return parts.join("+");
}
export function formatShortcut(shortcut) {
    try {
        return parseShortcut(shortcut).map(formatKeystroke).join(" ");
    }
    catch {
        return shortcut;
    }
}
export function getShortcutDisplay(action, context, fallback) {
    return getBindingDisplayText(action, context, loadKeybindingsSync()) ?? formatShortcut(fallback);
}
function displayKey(key) {
    if (key.length === 1)
        return key.toUpperCase();
    return key.slice(0, 1).toUpperCase() + key.slice(1);
}
