import { useState, useCallback } from 'react' import { motion, AnimatePresence } from 'framer-motion' import { AlertTriangle, CheckCircle, ChevronRight } from 'lucide-react' import { patient } from '@/data/patient' import { consultations } from '@/data/consultations' import { problems } from '@/data/problems' import { medications } from '@/data/medications' import type { ViewId, Problem, Medication, Consultation } from '@/types/pmr' // ─── Alert state machine ──────────────────────────────────────────────────── type AlertState = 'visible' | 'acknowledging' | 'dismissed' // ─── Props ────────────────────────────────────────────────────────────────── interface SummaryViewProps { onNavigate?: (view: ViewId, itemId?: string) => void } export function SummaryView({ onNavigate }: SummaryViewProps) { const [alertState, setAlertState] = useState('visible') const prefersReducedMotion = typeof window !== 'undefined' ? window.matchMedia('(prefers-reduced-motion: reduce)').matches : false const handleAcknowledge = useCallback(() => { if (prefersReducedMotion) { setAlertState('dismissed') return } setAlertState('acknowledging') // Icon crossfade (200ms) + hold beat (200ms) = 400ms before collapse const timer = setTimeout(() => { setAlertState('dismissed') }, 400) return () => clearTimeout(timer) }, [prefersReducedMotion]) const activeProblems = problems.filter( (p) => p.status === 'Active' || p.status === 'In Progress' ) const topMedications = medications .filter((m) => m.category === 'Active') .slice(0, 5) const lastConsultation = consultations[0] return (
{/* Clinical Alert */} {alertState !== 'dismissed' && ( )} {/* Summary cards grid */}
{/* Card 1: Demographics — full width */} {/* Card 2: Active Problems — left column */} {/* Card 3: Current Medications Quick View — right column */} {/* Card 4: Last Consultation — full width */}
) } // ─── Clinical Alert ───────────────────────────────────────────────────────── interface ClinicalAlertProps { state: AlertState onAcknowledge: () => void prefersReducedMotion: boolean } function ClinicalAlert({ state, onAcknowledge, prefersReducedMotion, }: ClinicalAlertProps) { const isAcknowledging = state === 'acknowledging' return (
{/* Icon area — crossfade between AlertTriangle and CheckCircle */}
{isAcknowledging ? ( ) : ( )}
{/* Message */}

ALERT: This patient has identified{' '} £14.6M in prescribing efficiency savings across Norfolk & Waveney ICS.

{/* Acknowledge button */}
) } // ─── Shared Card Components ───────────────────────────────────────────────── function CardHeader({ title }: { title: string }) { return (

{title}

) } // ─── Demographics Card ────────────────────────────────────────────────────── function DemographicsCard() { return (
{patient.status} } /> GPhC{' '} {patient.nhsNumber.replace(/ /g, '')} } />
) } interface DemographicsRowProps { label: string value: React.ReactNode mono?: boolean } function DemographicsRow({ label, value, mono }: DemographicsRowProps) { return (
{label}: {value}
) } // ─── Active Problems Card ─────────────────────────────────────────────────── interface ActiveProblemsCardProps { problems: Problem[] onNavigate?: (view: ViewId, itemId?: string) => void } function ActiveProblemsCard({ problems, onNavigate }: ActiveProblemsCardProps) { return (
{problems.map((problem) => ( ))}
) } // ─── Traffic Light (always with text label — guardrail) ───────────────────── interface TrafficLightProps { status: 'Active' | 'In Progress' | 'Resolved' } function TrafficLight({ status }: TrafficLightProps) { const config: Record< TrafficLightProps['status'], { dotClass: string; label: string } > = { Active: { dotClass: 'bg-green-500', label: 'Active' }, 'In Progress': { dotClass: 'bg-amber-500', label: 'In Progress' }, Resolved: { dotClass: 'bg-green-500', label: 'Resolved' }, } const { dotClass, label } = config[status] return ( ) } // ─── Quick Medications Card ───────────────────────────────────────────────── interface QuickMedsCardProps { medications: Medication[] onNavigate?: (view: ViewId) => void } function QuickMedsCard({ medications, onNavigate }: QuickMedsCardProps) { return (
{medications.map((med, index) => ( ))}
Drug Dose Freq Status
{med.name} {med.dose}% {med.frequency}
) } // ─── Last Consultation Card ───────────────────────────────────────────────── interface LastConsultationCardProps { consultation: Consultation onNavigate?: (view: ViewId, itemId?: string) => void } function LastConsultationCard({ consultation, onNavigate, }: LastConsultationCardProps) { return (
{consultation.date} | {consultation.organization}

{consultation.role}

{consultation.history}

) }