import { useState } from 'react' import { Send, Mail, Phone, MapPin, ExternalLink, Loader2, CheckCircle } from 'lucide-react' import { patient } from '@/data/patient' type Priority = 'urgent' | 'routine' | 'two-week-wait' type ContactMethod = 'email' | 'phone' | 'linkedin' interface FormData { priority: Priority referrerName: string referrerEmail: string referrerOrg: string reason: string contactMethod: ContactMethod } interface FormErrors { referrerName?: string referrerEmail?: string } const prefersReducedMotion = typeof window !== 'undefined' ? window.matchMedia('(prefers-reduced-motion: reduce)').matches : false function generateRefNumber(): string { const now = new Date() const year = now.getFullYear() const month = String(now.getMonth() + 1).padStart(2, '0') const day = String(now.getDate()).padStart(2, '0') const seq = String(Math.floor(Math.random() * 999) + 1).padStart(3, '0') return `REF-${year}-${month}${day}-${seq}` } function PriorityOption({ value, label, selected, tooltip, onSelect, }: { value: Priority label: string selected: boolean tooltip: string onSelect: () => void }) { const dotColors: Record = { urgent: 'bg-red-500', routine: 'bg-pmr-nhsblue', 'two-week-wait': 'bg-amber-500', } const labelColors: Record = { urgent: 'text-red-600', routine: 'text-pmr-nhsblue', 'two-week-wait': 'text-amber-600', } return ( ) } function ContactMethodOption({ value, label, selected, onSelect, }: { value: ContactMethod label: string selected: boolean onSelect: () => void }) { return ( ) } function FormField({ label, id, required, error, children, }: { label: string id: string required?: boolean error?: string children: React.ReactNode }) { return (
{children} {error &&

{error}

}
) } function DirectContactTable() { const contactMethods = [ { label: 'Email', value: patient.email, href: `mailto:${patient.email}`, action: 'Send Email', icon: Mail, }, { label: 'Phone', value: patient.phone, href: `tel:${patient.phone}`, action: 'Call', icon: Phone, }, { label: 'LinkedIn', value: patient.linkedin, href: `https://${patient.linkedin}`, action: 'View Profile', icon: ExternalLink, external: true, }, { label: 'Location', value: 'Norwich, UK', href: null, action: null, icon: MapPin, }, ] return (

Direct Contact

{contactMethods.map((method) => (
{method.label} {method.href ? ( {method.value} ) : ( {method.value} )}
{method.href && ( {method.action} {method.external && } )}
))}
) } export function ReferralsView() { const [formData, setFormData] = useState({ priority: 'routine', referrerName: '', referrerEmail: '', referrerOrg: '', reason: '', contactMethod: 'email', }) const [errors, setErrors] = useState({}) const [isSubmitting, setIsSubmitting] = useState(false) const [isSuccess, setIsSuccess] = useState(false) const [refNumber, setRefNumber] = useState('') const validateForm = (): boolean => { const newErrors: FormErrors = {} if (!formData.referrerName.trim()) { newErrors.referrerName = 'Referrer name is required' } if (!formData.referrerEmail.trim()) { newErrors.referrerEmail = 'Referrer email is required' } else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(formData.referrerEmail)) { newErrors.referrerEmail = 'Please enter a valid email address' } setErrors(newErrors) return Object.keys(newErrors).length === 0 } const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() if (!validateForm()) return setIsSubmitting(true) await new Promise((resolve) => setTimeout(resolve, 1000)) setRefNumber(generateRefNumber()) setIsSubmitting(false) setIsSuccess(true) } const handleReset = () => { setFormData({ priority: 'routine', referrerName: '', referrerEmail: '', referrerOrg: '', reason: '', contactMethod: 'email', }) setErrors({}) setIsSuccess(false) setRefNumber('') } if (isSuccess) { return (

New Referral

Referral sent successfully

Reference: {refNumber}

Expected response time: 24-48 hours

) } return (

New Referral

Contact Andy using a clinical referral form format.

Referring to {patient.name}
NHS Number {patient.nhsNumber}
Priority
setFormData({ ...formData, priority: 'urgent' })} /> setFormData({ ...formData, priority: 'routine' })} /> setFormData({ ...formData, priority: 'two-week-wait' })} />
setFormData({ ...formData, referrerName: e.target.value })} className="w-full border border-[#D1D5DB] rounded px-3 py-2 text-sm font-ui text-gray-900 placeholder-gray-400 focus:border-pmr-nhsblue focus:ring-2 focus:ring-pmr-nhsblue/15 focus:outline-none transition-all duration-200" placeholder="Your name" /> setFormData({ ...formData, referrerEmail: e.target.value })} className="w-full border border-[#D1D5DB] rounded px-3 py-2 text-sm font-ui text-gray-900 placeholder-gray-400 focus:border-pmr-nhsblue focus:ring-2 focus:ring-pmr-nhsblue/15 focus:outline-none transition-all duration-200" placeholder="your.email@example.com" />
setFormData({ ...formData, referrerOrg: e.target.value })} className="w-full border border-[#D1D5DB] rounded px-3 py-2 text-sm font-ui text-gray-900 placeholder-gray-400 focus:border-pmr-nhsblue focus:ring-2 focus:ring-pmr-nhsblue/15 focus:outline-none transition-all duration-200" placeholder="Organisation name (optional)" />