import React, { useState, useEffect } from 'react'; export interface Service { id: string; name: string; category: string; description?: string; } export interface ServiceLookupProps { isOpen: boolean; onClose: () => void; onServicesSelected: (services: Service[]) => void; selectedServices?: Service[]; allowMultiple?: boolean; title?: string; } const ServiceLookupComponent: React.FC = ({ isOpen, onClose, onServicesSelected, selectedServices = [], allowMultiple = true, title = "Service Lookup" }) => { const [searchTerm, setSearchTerm] = useState(''); const [selectedCategory, setSelectedCategory] = useState('All'); const [tempSelectedServices, setTempSelectedServices] = useState(selectedServices); // Service categories and their services const serviceCategories = { "Outpatient": [ { id: "op_psychotherapy", name: "Outpatient Psychotherapy", category: "Outpatient", description: "Individual therapy sessions" }, { id: "group_therapy", name: "Group Therapy", category: "Outpatient", description: "Therapeutic group sessions" }, { id: "family_therapy", name: "Family Therapy", category: "Outpatient", description: "Family counseling sessions" }, { id: "crisis_psychotherapy", name: "Crisis Psychotherapy", category: "Outpatient", description: "Emergency psychological intervention" }, { id: "medication_mgt", name: "Medication Management", category: "Outpatient", description: "Psychiatric medication oversight" }, { id: "evaluations", name: "Evaluations", category: "Outpatient", description: "Psychological assessments" }, { id: "consultations", name: "Consultations", category: "Outpatient", description: "Professional consultations" }, { id: "inhome_therapy", name: "In-Home Therapy", category: "Outpatient", description: "Therapy services at home" }, { id: "psych_testing", name: "Psychological Testing", category: "Outpatient", description: "If copay applies, will be per day" } ], "Inpatient": [ { id: "ip_psych", name: "IP Psych", category: "Inpatient", description: "Inpatient psychiatric care" }, { id: "ip_substance", name: "IP Substance", category: "Inpatient", description: "Inpatient substance abuse treatment" }, { id: "ip_detox", name: "IP Detox", category: "Inpatient", description: "Inpatient detoxification services" } ], "Professional Services": [ { id: "ip_prof_psych", name: "IP Professional Psych", category: "Professional Services", description: "Professional psychiatric services" }, { id: "ip_prof_sa", name: "IP Professional SA", category: "Professional Services", description: "Professional substance abuse services" }, { id: "medical_consults_bh", name: "Medical Consults on a BH Floor", category: "Professional Services", description: "Medical consultations on behavioral health floor" }, { id: "ip_prof_detox", name: "IP Prof Detox", category: "Professional Services", description: "Professional detoxification services" }, { id: "bh_consults_medical", name: "BH Consults on a Medical Floor", category: "Professional Services", description: "Behavioral health consultations on medical floor" }, { id: "ip_psych_testing", name: "IP Psych Testing", category: "Professional Services", description: "Inpatient psychological testing" }, { id: "methadone_maintenance", name: "Methadone Maintenance", category: "Professional Services", description: "Methadone treatment program" }, { id: "biofeedback", name: "Biofeedback", category: "Professional Services", description: "Biofeedback therapy" }, { id: "suboxone", name: "Suboxone", category: "Professional Services", description: "Suboxone treatment" }, { id: "hypnotherapy", name: "Hypnotherapy", category: "Professional Services", description: "Hypnosis therapy" }, { id: "tms", name: "TMS - Transcranial Magnetic Stimulation", category: "Professional Services", description: "Transcranial magnetic stimulation treatment" } ], "Alternative Levels of Care": [ { id: "group_home", name: "Group Home", category: "Alternative Levels of Care", description: "Residential group home care" }, { id: "halfway_house", name: "Halfway House", category: "Alternative Levels of Care", description: "Transitional residential care" }, { id: "iop", name: "IOP", category: "Alternative Levels of Care", description: "Intensive outpatient program" }, { id: "rtc", name: "RTC", category: "Alternative Levels of Care", description: "Residential treatment center" }, { id: "ambulatory_detox", name: "Ambulatory Detox", category: "Alternative Levels of Care", description: "Outpatient detoxification" }, { id: "partial_hosp", name: "Partial Hosp", category: "Alternative Levels of Care", description: "Partial hospitalization program" }, { id: "crisis_intervention", name: "Crisis Intervention", category: "Alternative Levels of Care", description: "Emergency crisis intervention" } ], "Emergency Services": [ { id: "er_facility", name: "ER Facility", category: "Emergency Services", description: "Emergency room facility services" }, { id: "er_professional", name: "ER Professional", category: "Emergency Services", description: "Emergency room professional services" }, { id: "ect_ip_facility", name: "ECT IP Facility", category: "Emergency Services", description: "Electroconvulsive therapy inpatient facility" }, { id: "ect_ip_professional", name: "ECT IP Professional", category: "Emergency Services", description: "Electroconvulsive therapy inpatient professional" }, { id: "ect_ip_anesthesia", name: "ECT IP Anesthesia", category: "Emergency Services", description: "Electroconvulsive therapy inpatient anesthesia" }, { id: "ect_op_facility", name: "ECT OP Facility", category: "Emergency Services", description: "Electroconvulsive therapy outpatient facility" }, { id: "ect_op_professional", name: "ECT OP Professional", category: "Emergency Services", description: "Electroconvulsive therapy outpatient professional" }, { id: "ect_op_anesthesia", name: "ECT OP Anesthesia", category: "Emergency Services", description: "Electroconvulsive therapy outpatient anesthesia" } ], "Other Services": [ { id: "op_labs_diagnostic", name: "OP Labs & Diagnostic Testing", category: "Other Services", description: "Outpatient laboratory and diagnostic testing" }, { id: "ip_labs_diagnostic", name: "IP Labs & Diagnostic Testing", category: "Other Services", description: "Inpatient laboratory and diagnostic testing" }, { id: "injections", name: "Injections", category: "Other Services", description: "Injectable medications and treatments" }, { id: "ambulance", name: "Ambulance", category: "Other Services", description: "Ambulance transportation services" } ] }; // Flatten all services for searching const allServices = Object.values(serviceCategories).flat(); // Filter services based on search term and category const filteredServices = allServices.filter(service => { const matchesSearch = service.name.toLowerCase().includes(searchTerm.toLowerCase()) || service.description?.toLowerCase().includes(searchTerm.toLowerCase()); const matchesCategory = selectedCategory === 'All' || service.category === selectedCategory; return matchesSearch && matchesCategory; }); // Reset temp selections when modal opens useEffect(() => { if (isOpen) { setTempSelectedServices(selectedServices); } }, [isOpen]); // Remove selectedServices from dependency array to prevent infinite loop const handleServiceToggle = (service: Service) => { if (allowMultiple) { setTempSelectedServices(prev => { const isSelected = prev.some(s => s.id === service.id); if (isSelected) { return prev.filter(s => s.id !== service.id); } else { return [...prev, service]; } }); } else { // For single selection, always set the clicked service as the only selection setTempSelectedServices([service]); } }; const handleConfirm = () => { onServicesSelected(tempSelectedServices); onClose(); }; const handleCancel = () => { setTempSelectedServices(selectedServices); onClose(); }; const isServiceSelected = (serviceId: string) => { return tempSelectedServices.some(s => s.id === serviceId); }; if (!isOpen) return null; return (
{/* Header */}

🔍 {title}

{/* Selection Summary */}
{tempSelectedServices.length === 0 ? ( `No services selected • ${allowMultiple ? 'Select multiple services' : 'Select a service'}` ) : ( `${tempSelectedServices.length} service${tempSelectedServices.length !== 1 ? 's' : ''} selected` )}
{/* Search and Filter Controls */}
{/* Search Input */}
setSearchTerm(e.target.value)} style={{ width: '100%', padding: '12px 16px', border: '2px solid #e2e8f0', borderRadius: '8px', fontSize: '14px', outline: 'none', transition: 'border-color 0.2s ease' }} onFocus={(e) => e.currentTarget.style.borderColor = '#667eea'} onBlur={(e) => e.currentTarget.style.borderColor = '#e2e8f0'} />
{/* Category Filter */}
{/* Quick Stats */}
📊 {filteredServices.length} services found 📂 {Object.keys(serviceCategories).length} categories
{/* Services List */}
{filteredServices.length === 0 ? (
🔍

No services found

Try adjusting your search terms or category filter

) : (
{Object.entries(serviceCategories).map(([categoryName, services]) => { const categoryServices = services.filter(service => filteredServices.some(fs => fs.id === service.id) ); if (categoryServices.length === 0) return null; return (
{selectedCategory === 'All' && (

{categoryName}

)} {categoryServices.map(service => (
handleServiceToggle(service)} style={{ padding: '16px', border: `2px solid ${isServiceSelected(service.id) ? '#667eea' : '#e2e8f0'}`, borderRadius: '8px', cursor: 'pointer', transition: 'all 0.2s ease', background: isServiceSelected(service.id) ? '#f0f4ff' : 'white', position: 'relative' }} onMouseEnter={(e) => { if (!isServiceSelected(service.id)) { e.currentTarget.style.borderColor = '#cbd5e1'; e.currentTarget.style.background = '#f8fafc'; } }} onMouseLeave={(e) => { if (!isServiceSelected(service.id)) { e.currentTarget.style.borderColor = '#e2e8f0'; e.currentTarget.style.background = 'white'; } }} >
{/* Selection Indicator */}
{isServiceSelected(service.id) && (allowMultiple ? '✓' : '●')}

{service.name}

{service.description && (

{service.description}

)}
{/* Category Badge */} {selectedCategory === 'All' && (
{service.category}
)}
))}
); })}
)}
{/* Footer Actions */}
{/* Selected Services Count */}
{tempSelectedServices.length > 0 && ( {tempSelectedServices.length} service{tempSelectedServices.length !== 1 ? 's' : ''} selected )}
{/* Action Buttons */}
); }; export default ServiceLookupComponent;