export const DEFAULT_SHORTCUTS = [
    // General shortcuts
    {
        key: "?",
        modifiers: ["Shift", "Control"],
        description: "Show keyboard shortcuts (Windows/Linux)",
        category: "General",
    },
    {
        key: "?",
        modifiers: ["Meta", "Shift"],
        description: "Show keyboard shortcuts (Mac)",
        category: "General",
    },
    {
        key: "Escape",
        description: "Close dialog or modal",
        category: "General",
    },
    // Chat shortcuts
    {
        key: "Enter",
        description: "Send message",
        category: "Chat",
    },
    {
        key: "Enter",
        modifiers: ["Shift"],
        description: "New line in message",
        category: "Chat",
    },
    // {
    //   key: "K",
    //   modifiers: ["Meta"],
    //   description: "Open search (Mac)",
    //   category: "Chat",
    // },
    // {
    //   key: "K",
    //   modifiers: ["Control"],
    //   description: "Open search (Windows/Linux)",
    //   category: "Chat",
    // },
    {
        key: "H",
        modifiers: ["Meta"],
        description: "Show chat history (Mac)",
        category: "Chat",
    },
    {
        key: "H",
        modifiers: ["Control"],
        description: "Show chat history (Windows/Linux)",
        category: "Chat",
    },
    // Navigation shortcuts
    {
        key: "ArrowUp",
        description: "Navigate to previous message",
        category: "Navigation",
    },
    {
        key: "ArrowDown",
        description: "Navigate to next message",
        category: "Navigation",
    },
    {
        key: "/",
        description: "Focus search input",
        category: "Navigation",
    },
    // Accessibility shortcuts
    {
        key: "Tab",
        description: "Navigate between elements",
        category: "Accessibility",
    },
    {
        key: "Tab",
        modifiers: ["Shift"],
        description: "Navigate backward",
        category: "Accessibility",
    },
];
export class KeyboardShortcutManager {
    constructor() {
        this.shortcuts = new Map();
        this.isEnabled = true;
    }
    /**
     * Register a keyboard shortcut handler
     */
    register(key, modifiers, handler) {
        const shortcutKey = this.createShortcutKey(key, modifiers);
        this.shortcuts.set(shortcutKey, handler);
    }
    /**
     * Unregister a keyboard shortcut
     */
    unregister(key, modifiers) {
        const shortcutKey = this.createShortcutKey(key, modifiers);
        this.shortcuts.delete(shortcutKey);
    }
    /**
     * Handle keyboard event
     */
    handleKeyboardEvent(event) {
        if (!this.isEnabled)
            return false;
        // Don't trigger shortcuts when typing in input/textarea (except Enter)
        const target = event.target;
        const isInputElement = target.tagName === 'INPUT' || target.tagName === 'TEXTAREA';
        if (isInputElement && event.key !== 'Enter' && event.key !== 'Escape') {
            return false;
        }
        const modifiers = [];
        if (event.metaKey)
            modifiers.push('Meta');
        if (event.ctrlKey)
            modifiers.push('Control');
        if (event.altKey)
            modifiers.push('Alt');
        if (event.shiftKey)
            modifiers.push('Shift');
        const shortcutKey = this.createShortcutKey(event.key, modifiers);
        const handler = this.shortcuts.get(shortcutKey);
        if (handler) {
            event.preventDefault();
            event.stopPropagation();
            handler();
            return true;
        }
        return false;
    }
    /**
     * Enable or disable all shortcuts
     */
    setEnabled(enabled) {
        this.isEnabled = enabled;
    }
    /**
     * Clear all registered shortcuts
     */
    clear() {
        this.shortcuts.clear();
    }
    /**
     * Create a unique key for the shortcut
     */
    createShortcutKey(key, modifiers) {
        const sortedModifiers = [...modifiers].sort();
        return [...sortedModifiers, key].join('+');
    }
}
/**
 * Singleton instance
 */
export const shortcutManager = new KeyboardShortcutManager();
