import React, { useEffect, useRef } from 'react'; import { cn } from "@/lib/utils"; interface Skill { id: string; name: string; description?: string; type: string; } interface SlashCommandMenuProps { isOpen: boolean; skills: Skill[]; selectedIndex: number; onSelect: (skill: Skill) => void; onClose: () => void; } export function SlashCommandMenu({ isOpen, skills, selectedIndex, onSelect, onClose }: SlashCommandMenuProps) { const menuRef = useRef(null); const selectedRef = useRef(null); useEffect(() => { if (isOpen && selectedRef.current) { selectedRef.current.scrollIntoView({ block: 'nearest' }); } }, [isOpen, selectedIndex]); // Click outside to close useEffect(() => { const handleClickOutside = (event: MouseEvent) => { if (menuRef.current && !menuRef.current.contains(event.target as Node)) { onClose(); } }; if (isOpen) { document.addEventListener('mousedown', handleClickOutside); } return () => { document.removeEventListener('mousedown', handleClickOutside); }; }, [isOpen, onClose]); if (!isOpen || skills.length === 0) return null; return (
{skills.map((skill, index) => ( ))}
); }