"use client"; import React, { useState, useCallback } from "react"; import type { PredictionResult, CausalAgentType } from "@/lib/types"; import ConfidenceBadge, { getConfidenceColors } from "@/components/ConfidenceBadge"; import SymptomChecker from "@/components/SymptomChecker"; import TreatmentTimeline, { treatmentStepsWithUrgency } from "@/components/TreatmentTimeline"; import LookalikeWarning from "@/components/LookalikeWarning"; import FlagButton from "@/components/FlagButton"; /** * Individual disease result card with expandable sections. * * Collapsed state: disease name, confidence badge, causal agent type icon, one-sentence summary. * Expanded state: full description, symptom list, cause list, treatment timeline, prevention tips. * Smooth expand/collapse animation. * "Was this helpful?" feedback buttons at the bottom. */ export default function DiseaseCard({ prediction, rank, isPrimary, onDismiss, }: { prediction: PredictionResult; rank: number; isPrimary: boolean; onDismiss?: () => void; }) { const [expanded, setExpanded] = useState(isPrimary); const [feedback, setFeedback] = useState<"yes" | "no" | null>(null); const { disease, confidence, lookalikeDiseases } = prediction; const colors = getConfidenceColors(confidence.label); const lookalikes = lookalikeDiseases ?? []; const toggleExpand = useCallback(() => { setExpanded((e) => !e); }, []); // One-sentence summary (first sentence of description) const summary = disease.description.split(".")[0] + "."; return (
{/* Primary diagnosis ribbon */} {isPrimary && (
Primary Diagnosis
)} {/* Card header — clickable to expand/collapse */} {/* Card body — expandable content */}

{/* Full description */}

Description

{disease.description}

{/* Symptom checker */}

Symptom Checker

{/* Causes */}

Causes & Contributing Factors

    {disease.causes.map((cause, i) => (
  • {cause}
  • ))}
{/* Treatment timeline */}

Treatment Plan

{/* Prevention tips */}

Prevention Tips

    {disease.prevention.map((tip, i) => (
  • {tip}
  • ))}
{/* Lookalike warnings */} {lookalikes.length > 0 && } {/* Feedback buttons */}

Was this diagnosis helpful?

{feedback && ( Thanks for your feedback! )}
{/* Dismiss button (top-right corner, visible on hover) */} {onDismiss && ( )}
); } /** * Causal agent type icon — shows a small icon based on disease type. */ function CausalAgentIcon({ type }: { type: CausalAgentType }) { const config = getCausalAgentConfig(type); return ( {config.icon} {config.label} ); } interface CausalAgentConfig { label: string; bg: string; text: string; icon: React.ReactNode; } function getCausalAgentConfig(type: CausalAgentType): CausalAgentConfig { switch (type) { case "fungal": return { label: "Fungal", bg: "bg-purple-100 dark:bg-purple-900/50", text: "text-purple-700 dark:text-purple-300", icon: ( ), }; case "bacterial": return { label: "Bacterial", bg: "bg-blue-100 dark:bg-blue-900/50", text: "text-blue-700 dark:text-blue-300", icon: ( ), }; case "viral": return { label: "Viral", bg: "bg-pink-100 dark:bg-pink-900/50", text: "text-pink-700 dark:text-pink-300", icon: ( ), }; case "environmental": return { label: "Environmental", bg: "bg-orange-100 dark:bg-orange-900/50", text: "text-orange-700 dark:text-orange-300", icon: ( ), }; } }