'use client'; import React, { useState } from 'react'; import { Patient, ClinicTenant } from '@/types/clinical'; import { Users, AlertTriangle, MessageSquare, TrendingUp, CheckCircle, Clock, Sparkles, PhoneCall, Calendar, Send, X, } from 'lucide-react'; interface RetentionViewProps { patients: Patient[]; activeTenant: ClinicTenant; onSelectPatientChart: (patient: Patient) => void; } export const RetentionView: React.FC = ({ patients, activeTenant, onSelectPatientChart, }) => { const [selectedPatientForSms, setSelectedPatientForSms] = useState(null); const [customSmsMessage, setCustomSmsMessage] = useState(''); const [isSendingSms, setIsSendingSms] = useState(false); const [sentToast, setSentToast] = useState(false); const [filterType, setFilterType] = useState<'all' | 'dropout_risk' | 'active'>('dropout_risk'); const dropoutPatients = patients.filter((p) => p.status === 'dropout_risk'); const activePatients = patients.filter((p) => p.status === 'active'); const displayedPatients = filterType === 'dropout_risk' ? dropoutPatients : filterType === 'active' ? activePatients : patients; const handleOpenSmsModal = (patient: Patient) => { setSelectedPatientForSms(patient); setCustomSmsMessage( `Hi ${patient.firstName}! Dr. Vance noticed you're due for visit ${ patient.carePlan.completedVisits + 1 } of your ${patient.carePlan.title}. We want to make sure your progress stays on track! Click here to pick a quick 15-min adjustment slot this week: https://${ activeTenant.domain }/book?ref=careplan` ); }; const handleSendSms = () => { setIsSendingSms(true); setTimeout(() => { setIsSendingSms(false); setSentToast(true); if (selectedPatientForSms) { selectedPatientForSms.status = 'reactivated'; } setTimeout(() => { setSentToast(false); setSelectedPatientForSms(null); }, 1500); }, 1000); }; return (
{/* Top Value Metric Cards */}
Care Plan Retention
84.2%

+18% higher than Jane App

Patients at Dropout Risk
{dropoutPatients.length} Patients

Missed expected cadence > 10 days

Revenue at Risk $
$2,140.00

Unbilled care plan visits

Recovered This Month
+$3,850.00

Via AI Autonomous SMS

{/* Main Table / Patient List Header */}

Care Plan Adherence & Reactivation Radar

Identifies patients who have dropped off their prescribed spinal treatment plans before completing their clinical goals.

{/* Patient Rows */}
{displayedPatients.map((p) => { const isAtRisk = p.status === 'dropout_risk'; const progressPct = Math.round( (p.carePlan.completedVisits / p.carePlan.totalVisits) * 100 ); return (

{p.firstName} {p.lastName}

{isAtRisk ? ( {p.daysSinceLastVisit} Days Since Visit ) : ( On Track )}

Care Plan: {p.carePlan.title} ({p.carePlan.frequency})

{p.carePlan.completedVisits}/{p.carePlan.totalVisits}
Phone: {p.phone} Last Visit: {p.lastVisitDate}
{/* Actions */}
); })}
{/* SMS Reactivation Modal */} {selectedPatientForSms && (

Autonomous SMS Reactivation Dispatch

To: {selectedPatientForSms.firstName} {selectedPatientForSms.lastName} ({selectedPatientForSms.phone})

Sending Clinic Line:{' '} {activeTenant.phone}
AI Pilots Gateway