import { useRef, useEffect, type ComponentType, type SVGAttributes } from 'react' import { cn } from '@/lib/utils' import { Badge } from '@/components/ui/badge' import { NoteTitleIcon } from './NoteTitleIcon' export interface NoteSearchResultItem { title: string noteIcon?: string | null noteType?: string typeColor?: string typeLightColor?: string TypeIcon?: ComponentType> } 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.TypeIcon && ( )} {item.title} {item.noteType && ( {item.noteType} )}
))}
) }