"use client"; import Link from "next/link"; import { Suspense, useEffect, useState } from "react"; import { useSearchParams } from "next/navigation"; type SeverityInfo = { label: string; color: string; description: string; }; type ResultData = { scores: number[]; total_score: number; severity: SeverityInfo; filler_count: number; negative_words: string[]; positive_words: string[]; item_names: string[]; answers: string[]; questions: string[]; itemShortNames: string[]; date: string; fallback?: boolean; }; const SEVERITY_STYLES: Record = { Minimal: { bg: "bg-green-50", text: "text-green-700", border: "border-green-200" }, Mild: { bg: "bg-amber-50", text: "text-amber-700", border: "border-amber-200" }, Moderate: { bg: "bg-orange-50", text: "text-orange-700", border: "border-orange-200" }, "Moderately Severe": { bg: "bg-red-50", text: "text-red-600", border: "border-red-200" }, Severe: { bg: "bg-red-100", text: "text-red-800", border: "border-red-300" }, }; const BAR_COLORS = [ "bg-primary", "bg-primary-container", "bg-[#F57C00]", "bg-error", ]; function getBarColor(score: number): string { const idx = Math.min(Math.round(score), 3); return BAR_COLORS[idx]; } const SHORT_NAMES = [ "Loss of Interest", "Feeling Depressed", "Sleep Issues", "Fatigue", "Appetite Changes", "Self-Criticism", "Concentration", "Psychomotor", ]; function ResultContent() { const searchParams = useSearchParams(); const [result, setResult] = useState(null); useEffect(() => { const historyId = searchParams.get("id"); if (historyId !== null) { /* Load from history */ const historyRaw = localStorage.getItem("mindcheck_history"); if (historyRaw) { try { const history = JSON.parse(historyRaw) as ResultData[]; const idx = parseInt(historyId, 10); if (history[idx]) setResult(history[idx]); } catch { /* ignore */ } } } else { /* Load latest result */ const raw = localStorage.getItem("mindcheck_latest_result"); if (raw) { try { setResult(JSON.parse(raw)); } catch { /* ignore */ } } } }, [searchParams]); const handleSave = () => { if (!result) return; const historyRaw = localStorage.getItem("mindcheck_history"); const history: ResultData[] = historyRaw ? JSON.parse(historyRaw) : []; history.unshift(result); localStorage.setItem("mindcheck_history", JSON.stringify(history)); alert("Results saved to history!"); }; if (!result) { return ( <>
MindCheck
Screening Results
Start Screening
assignment_late

No Results Available

Complete a screening first to see your results.

Start Screening
); } const sevStyle = SEVERITY_STYLES[result.severity.label] || SEVERITY_STYLES.Moderate; const maxScore = 24; return ( <> {/* TopNavBar */}
MindCheck
Screening Results
Restart Screening
{/* Main Content */}
{/* Left Column: Core Results */}
{/* Score Section */}

Your Result

{Math.round(result.total_score)} /{maxScore}
{result.severity.label}

{result.severity.description}

{result.fallback && (
warning Scored using keyword matching (model server unavailable)
)}

Screened on {new Date(result.date).toLocaleDateString("en-US", { day: "numeric", month: "long", year: "numeric", hour: "2-digit", minute: "2-digit" })}

{/* Bar Chart Section */}

Score per question

{result.scores.map((score, i) => { const name = result.itemShortNames?.[i] || SHORT_NAMES[i] || `Q${i + 1}`; const displayScore = score + 1; const pct = Math.min((displayScore / 4) * 100, 100); return (
{name}
{displayScore.toFixed(1)}
); })}
{/* Disclaimer */}
info

MindCheck is not a replacement for professional medical diagnosis. Please contact mental health professionals if you are in an emergency.

{/* Right Column: Metrics & Actions */}
{/* 2x2 Metric Grid */}
Total Score {Math.round(result.total_score)}
Category {result.severity.label}
Negative Words {result.negative_words.length} {result.negative_words.length > 0 && (
{result.negative_words.slice(0, 5).map((w) => ( {w} ))} {result.negative_words.length > 5 && ( +{result.negative_words.length - 5} more )}
)}
Filler Words {result.filler_count}
{/* Recommendation Card */}

Recommended Next Steps

{result.total_score <= 4 ? "Your results suggest minimal symptoms. Continue monitoring your well-being and maintain healthy habits." : result.total_score <= 9 ? "Your results suggest mild symptoms. Consider speaking with a trusted friend or family member, and monitor your progress." : result.total_score <= 14 ? "Based on these results, we recommend scheduling a consultation with a mental health professional for further evaluation." : "Based on these results, we strongly recommend seeking professional help immediately. Please contact a psychologist, psychiatrist, or your nearest mental health service."}

{/* Action Buttons */}
View History
); } export default function ResultPage() { return (
}>
); }