'use client'; import { useTranslations } from 'next-intl'; import { Button } from '@/components/ui/shared/Button'; import { PatientSearchCombobox } from '@/components/ui/patient/PatientSearchCombobox'; import { usePatientSearchQuery } from '@/lib/hooks/usePatientSearchQuery'; import { formatMobileForDisplay } from '@/lib/phone'; import type { Patient } from '@/types/patient'; const pickerChoiceClass = 'w-full rounded-[var(--radius-md)] border border-primary/40 bg-primary-soft px-3 py-2 text-start transition-colors hover:border-primary disabled:opacity-50 disabled:cursor-not-allowed focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/45'; interface NewTreatmentPatientPickerProps { creating?: boolean; currentPatient?: { id: string; displayName: string; mobile?: string | null; email?: string | null; } | null; onSelectWalkIn: () => void | Promise; onSelectPatient: (patient: Patient) => void | Promise; onSelectCurrentPatient?: () => void | Promise; onCancel: () => void; } function contactLine( patient: { mobile?: string | null; email?: string | null }, fallback: string, ): string { const mobile = patient.mobile?.trim() ? formatMobileForDisplay(patient.mobile.trim()) : ''; if (mobile) return mobile; const email = patient.email?.trim(); if (email) return email; return fallback; } export function NewTreatmentPatientPicker({ creating = false, currentPatient = null, onSelectWalkIn, onSelectPatient, onSelectCurrentPatient, onCancel, }: NewTreatmentPatientPickerProps) { const t = useTranslations('treatment'); const tCommon = useTranslations('common'); const tPatients = useTranslations('patients'); const { search, setSearch, patients, loading } = usePatientSearchQuery(!creating); return (

{t('newTreatmentPatientPrompt')}

{currentPatient && onSelectCurrentPatient ? ( ) : null} { if (creating) return; void onSelectPatient(patient); }} placeholder={tPatients('searchPlaceholder')} emptyResultsMessage={tPatients('noResults')} />
); }