import { useEffect, useRef } from 'react' interface FileSuggestionsProps { isOpen: boolean files: string[] onSelect: (file: string) => void onClose: () => void selectedIndex?: number } export function FileSuggestions({ isOpen, files, onSelect, onClose, selectedIndex = 0 }: FileSuggestionsProps) { const listRef = useRef(null) useEffect(() => { if (!isOpen) return const handleClickOutside = (e: MouseEvent) => { if (listRef.current && !listRef.current.contains(e.target as Node)) { onClose() } } document.addEventListener('mousedown', handleClickOutside) return () => document.removeEventListener('mousedown', handleClickOutside) }, [isOpen, onClose]) useEffect(() => { if (!isOpen || !listRef.current) return const selectedItem = listRef.current.children[selectedIndex] as HTMLElement if (selectedItem) { selectedItem.scrollIntoView({ block: 'nearest' }) } }, [selectedIndex, isOpen]) if (!isOpen || files.length === 0) return null const getFilename = (path: string) => path.split('/').pop() || path const getDirectory = (path: string) => { const parts = path.split('/') return parts.slice(0, -1).join('/') || '.' } return (
{files.map((file, idx) => ( ))}
) }