import { useEffect } from 'react'; import { X, Keyboard } from 'lucide-react'; import { useTranslation } from 'react-i18next'; import { Card, CardContent } from './Card'; interface NavItem { id: string; to: string; labelKey: string; } interface KeyboardShortcutsModalProps { onClose: () => void; navItems?: NavItem[]; } function getShortcuts(navItems: NavItem[] | undefined, t: (key: string) => string) { const navShortcuts = navItems ? navItems.map((item, index) => ({ keys: [String(index + 1)], description: `Go to ${t(item.labelKey)}`, })) : [ { keys: ['1'], description: 'Go to Printers' }, { keys: ['2'], description: 'Go to Archives' }, { keys: ['3'], description: 'Go to Queue' }, { keys: ['4'], description: 'Go to Statistics' }, { keys: ['5'], description: 'Go to Cloud Profiles' }, { keys: ['6'], description: 'Go to Settings' }, ]; return [ { category: 'Navigation', items: navShortcuts }, { category: 'Archives', items: [ { keys: ['/'], description: 'Focus search' }, { keys: ['U'], description: 'Open upload modal' }, { keys: ['Esc'], description: 'Clear selection / blur input' }, { keys: ['Right-click'], description: 'Context menu on cards' }, ]}, { category: 'K-Profiles', items: [ { keys: ['R'], description: 'Refresh profiles' }, { keys: ['N'], description: 'New profile' }, { keys: ['Esc'], description: 'Exit selection mode' }, ]}, { category: 'General', items: [ { keys: ['?'], description: 'Show this help' }, ]}, ]; } function KeyBadge({ children }: { children: string }) { return ( {children} ); } export function KeyboardShortcutsModal({ onClose, navItems }: KeyboardShortcutsModalProps) { const { t } = useTranslation(); const shortcuts = getShortcuts(navItems, t); // Close on Escape key useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose(); }; window.addEventListener('keydown', handleKeyDown); return () => window.removeEventListener('keydown', handleKeyDown); }, [onClose]); return (
e.stopPropagation()}> {/* Header */}

Keyboard Shortcuts

{/* Shortcuts List */}
{shortcuts.map((section) => (

{section.category}

{section.items.map((shortcut) => (
{shortcut.description}
{shortcut.keys.map((key) => ( {key} ))}
))}
))}
{/* Footer */}

Press Esc or click outside to close

); }