'use client' import { useState } from 'react' import { useRouter } from 'next/navigation' import { Calendar, Clock, Target } from 'lucide-react' import { Card, Button, showToast } from '@/components/ui' interface TreatmentPlanFormProps { workspaceId: string initialData?: { title: string totalCycles: number startDate: string cycleType: string cycleDays: number } } const CYCLE_TYPES = [ { value: 'WEEKLY', label: 'Weekly', days: 7 }, { value: 'BIWEEKLY', label: 'Every 2 weeks', days: 14 }, { value: 'MONTHLY', label: 'Monthly', days: 30 }, { value: 'CUSTOM', label: 'Custom', days: 0 }, ] export function TreatmentPlanForm({ workspaceId, initialData }: TreatmentPlanFormProps) { const router = useRouter() const [title, setTitle] = useState(initialData?.title || '') const [totalCycles, setTotalCycles] = useState(initialData?.totalCycles || 12) const [startDate, setStartDate] = useState(initialData?.startDate || '') const [cycleType, setCycleType] = useState(initialData?.cycleType || 'WEEKLY') const [customDays, setCustomDays] = useState(initialData?.cycleDays || 14) const [saving, setSaving] = useState(false) const selectedCycleType = CYCLE_TYPES.find(t => t.value === cycleType) const cycleDays = cycleType === 'CUSTOM' ? customDays : (selectedCycleType?.days || 7) // Calculate estimated end date const estimatedEndDate = startDate ? new Date(new Date(startDate).getTime() + (cycleDays * totalCycles * 24 * 60 * 60 * 1000)) : null const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() if (!title.trim()) { showToast('Please enter a treatment name', 'error') return } if (!startDate) { showToast('Please select a start date', 'error') return } setSaving(true) try { const response = await fetch(`/api/workspaces/${workspaceId}/treatment-plan`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ title: title.trim(), totalCycles, startDate, cycleType, cycleDays, }), }) if (!response.ok) throw new Error('Failed to create plan') showToast('Treatment plan created!', 'success') router.push('/treatment') } catch { showToast('Failed to create plan', 'error') } finally { setSaving(false) } } return (
{/* Treatment Name */}
setTitle(e.target.value)} placeholder="e.g., Grace's Chemotherapy Plan" className="w-full px-3 py-2 border border-border rounded-lg text-base focus:outline-none focus:ring-2 focus:ring-primary-200 focus:border-primary-500" required />
{/* Total Cycles */}
setTotalCycles(parseInt(e.target.value))} className="flex-1" /> setTotalCycles(parseInt(e.target.value) || 1)} className="w-20 px-3 py-2 border border-border rounded-lg text-center" />

Number of chemo sessions or treatment cycles

{/* Start Date */}
setStartDate(e.target.value)} className="w-full px-3 py-2 border border-border rounded-lg text-base focus:outline-none focus:ring-2 focus:ring-primary-200 focus:border-primary-500" required />
{/* Cycle Frequency */}
{CYCLE_TYPES.map((type) => ( ))}
{/* Custom Days Input */} {cycleType === 'CUSTOM' && (
setCustomDays(parseInt(e.target.value) || 1)} className="w-full px-3 py-2 border border-border rounded-lg text-base focus:outline-none focus:ring-2 focus:ring-primary-200 focus:border-primary-500" />
)} {/* Estimated End Date */} {estimatedEndDate && (

Estimated completion:

{estimatedEndDate.toLocaleDateString('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' })}

)} {/* Submit */}
) }