import { useState, useEffect, useRef } from 'react' import { ChevronDown, ChevronUp, ExternalLink } from 'lucide-react' import { problems } from '@/data/problems' import { consultations } from '@/data/consultations' import type { Problem, Consultation } from '@/types/pmr' interface ProblemsViewProps { onNavigate?: (view: 'consultations', itemId?: string) => void } type ProblemStatus = 'Active' | 'In Progress' | 'Resolved' function TrafficLight({ status }: { status: ProblemStatus }) { const colorMap: Record = { Active: { bg: 'bg-green-500', label: 'Active' }, 'In Progress': { bg: 'bg-amber-500', label: 'In Progress' }, Resolved: { bg: 'bg-green-500', label: 'Resolved' }, } const { bg, label } = colorMap[status] return (
{label}
) } function ProblemRow({ problem, isExpanded, onToggle, onNavigate, showOutcome, }: { problem: Problem isExpanded: boolean onToggle: () => void onNavigate?: (view: 'consultations', itemId?: string) => void showOutcome: boolean }) { const contentRef = useRef(null) const [contentHeight, setContentHeight] = useState(undefined) const prefersReducedMotion = useRef( window.matchMedia('(prefers-reduced-motion: reduce)').matches ).current useEffect(() => { if (contentRef.current) { setContentHeight(contentRef.current.scrollHeight) } }, [isExpanded]) const linkedConsultations = (problem.linkedConsultations ?? []) .map((id) => consultations.find((c) => c.id === id)) .filter((c): c is Consultation => c !== undefined) const handleLinkedClick = (consultationId: string) => { if (onNavigate) { onNavigate('consultations', consultationId) } } return ( <> [{problem.code}] {problem.description} {problem.resolved || problem.since} {showOutcome && ( {problem.outcome && ( {problem.outcome} )} )}
{problem.narrative}
{linkedConsultations.length > 0 && (
Linked Consultations:
{linkedConsultations.map((consultation) => ( ))}
)}
) } export function ProblemsView({ onNavigate }: ProblemsViewProps) { const [expandedId, setExpandedId] = useState(null) const activeProblems = problems.filter( (p) => p.status === 'Active' || p.status === 'In Progress' ) const resolvedProblems = problems.filter((p) => p.status === 'Resolved') const handleToggle = (id: string) => { setExpandedId(expandedId === id ? null : id) } return (

Active Problems

{activeProblems.map((problem) => ( handleToggle(problem.id)} onNavigate={onNavigate} showOutcome={false} /> ))}
Status Code Problem Since Expand
{activeProblems.length === 0 && (
No active problems
)}

Resolved Problems

{resolvedProblems.map((problem) => ( handleToggle(problem.id)} onNavigate={onNavigate} showOutcome={true} /> ))}
Status Code Problem Resolved Outcome Expand
{resolvedProblems.length === 0 && (
No resolved problems
)}
) }