import { useEffect, useState } from 'react' import { createPortal } from 'react-dom' import { X } from 'lucide-react' import { useLocale } from '@meshkee/dashboard-ui' import type { BusinessCustomer } from '../services/customerService' import { useT } from '../i18n/useT' import { CustomerSearchSelect } from './CustomerSearchSelect' import modalStyles from './VariationsModal.module.css' import styles from './AddWorkshopRegistrationModal.module.css' interface AddWorkshopRegistrationModalProps { open: boolean excludeIds: string[] isAdding: boolean error?: string onClose: () => void onPick: (customer: BusinessCustomer) => void } const ANIMATION_MS = 220 export function AddWorkshopRegistrationModal({ open, excludeIds, isAdding, error = '', onClose, onPick, }: AddWorkshopRegistrationModalProps) { const t = useT() const { locale } = useLocale() const isFa = locale === 'fa' const [mounted, setMounted] = useState(open) const [closing, setClosing] = useState(false) useEffect(() => { if (open) { setMounted(true) setClosing(false) } else if (mounted) { setClosing(true) const timer = setTimeout(() => { setMounted(false) setClosing(false) }, ANIMATION_MS) return () => clearTimeout(timer) } }, [open, mounted]) useEffect(() => { if (!mounted || closing) return const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose() } document.addEventListener('keydown', onKey) return () => document.removeEventListener('keydown', onKey) }, [mounted, closing, onClose]) if (!mounted) return null return createPortal(
e.stopPropagation()} role="dialog" aria-modal="true" aria-labelledby="add-workshop-registration-title" lang={isFa ? 'fa' : 'en'} dir={isFa ? 'rtl' : 'ltr'} >

{t('workshop.registrations.add')}

{error ? (

{error}

) : null}
undefined} onPick={onPick} excludeIds={excludeIds} disabled={isAdding} placeholder={t('workshop.registrations.searchPlaceholder')} />

{t('workshop.registrations.searchHint')}

, document.body, ) }