'use client'; /** * PatientMentionDropdown Component * * Dropdown for @mention patient selection in CommandInput. * Positioned above the input, shows search results. * * Epic: E2.S2 (Patient Selectie - @Mention) */ import { useEffect } from 'react'; import { usePatientSearch, type PatientSearchResult } from '@/lib/cortex/hooks/use-patient-search'; import { PatientListItem, PatientListEmpty, PatientListLoading, } from '@/components/cortex/shared/patient-list-item'; interface PatientMentionDropdownProps { /** Current search query (text after @) */ query: string; /** Called when a patient is selected */ onSelect: (patient: PatientSearchResult) => void; /** Called when dropdown should close */ onClose: () => void; } export function PatientMentionDropdown({ query, onSelect, onClose, }: PatientMentionDropdownProps) { const { setQuery, results, isSearching } = usePatientSearch({ debounceMs: 150, limit: 5, minQueryLength: 2, }); // Sync query to search hook useEffect(() => { setQuery(query); }, [query, setQuery]); // Close on Escape useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); onClose(); } }; document.addEventListener('keydown', handleKeyDown); return () => document.removeEventListener('keydown', handleKeyDown); }, [onClose]); return (
{isSearching ? ( ) : query.length < 2 ? (
Typ minimaal 2 karakters
) : results.length > 0 ? (
{results.map((patient) => ( onSelect(patient)} size="sm" /> ))}
) : ( )}
); }