"use client"; import { useEffect, useRef } from "react"; import { useTranslations } from "next-intl"; import { X, Keyboard } from "lucide-react"; import { KEYBOARD_SHORTCUTS } from "@/hooks/use-keyboard-shortcuts"; import { cn } from "@/lib/utils"; interface KeyboardShortcutsModalProps { isOpen: boolean; onClose: () => void; } export function KeyboardShortcutsModal({ isOpen, onClose }: KeyboardShortcutsModalProps) { const t = useTranslations(); const modalRef = useRef(null); // Close on any key press useEffect(() => { const handleKeyDown = () => { onClose(); }; if (isOpen) { window.addEventListener("keydown", handleKeyDown); return () => window.removeEventListener("keydown", handleKeyDown); } }, [isOpen, onClose]); // Close on click outside useEffect(() => { const handleClickOutside = (e: MouseEvent) => { if (modalRef.current && !modalRef.current.contains(e.target as Node)) { onClose(); } }; if (isOpen) { document.addEventListener("mousedown", handleClickOutside); return () => document.removeEventListener("mousedown", handleClickOutside); } }, [isOpen, onClose]); if (!isOpen) return null; return (
{/* Header */}

{t("shortcuts.title")}

{/* Content */}
{/* Navigation Section */}

{t("shortcuts.sections.navigation")}

{KEYBOARD_SHORTCUTS.navigation.map((shortcut) => ( ))}
{/* Actions Section */}

{t("shortcuts.sections.actions")}

{KEYBOARD_SHORTCUTS.actions.map((shortcut) => ( ))}
{/* Global Section */}

{t("shortcuts.sections.global")}

{KEYBOARD_SHORTCUTS.global.map((shortcut) => ( ))}
{/* Threads Section */}

{t("shortcuts.sections.threads")}

{KEYBOARD_SHORTCUTS.threads.map((shortcut) => ( ))}
{/* Footer tip */}

{t("shortcuts.tip")}

); } function ShortcutRow({ shortcutKey, description, }: { shortcutKey: string; description: string; }) { // Split keys by " / " to render multiple key badges const keys = shortcutKey.split(" / "); return (
{description}
{keys.map((key, index) => ( {index > 0 && or} {key} ))}
); }