import { useRef, useEffect } from 'react' import { cn } from '@/lib/utils' import { Badge } from '@/components/ui/badge' export interface NoteSearchResultItem { title: string noteType?: string typeColor?: string } interface NoteSearchListProps { items: T[] selectedIndex: number getItemKey: (item: T, index: number) => string onItemClick: (item: T, index: number) => void onItemHover?: (index: number) => void emptyMessage?: string className?: string } export function NoteSearchList({ items, selectedIndex, getItemKey, onItemClick, onItemHover, emptyMessage = 'No results', className, }: NoteSearchListProps) { const listRef = useRef(null) useEffect(() => { if (!listRef.current) return const el = listRef.current.children[selectedIndex] as HTMLElement | undefined el?.scrollIntoView({ block: 'nearest' }) }, [selectedIndex]) if (items.length === 0) { return (
{emptyMessage}
) } return (
{items.map((item, i) => (
onItemClick(item, i)} onMouseEnter={() => onItemHover?.(i)} > {item.title} {item.noteType && ( {item.noteType} )}
))}
) }