"use client"; import { useState } from "react"; import { motion, AnimatePresence } from "framer-motion"; import { LineChart, Line, XAxis, Tooltip, ResponsiveContainer } from "recharts"; import { useGUCStore } from "@/lib/store"; import MoodCheckIn from "@/components/MoodCheckIn"; import BreathingWidget from "@/components/BreathingWidget"; import { PageShell } from "@/components/ui"; const AFFIRMATIONS = { high_stress: [ "You came to the right place. Take 5 slow breaths right now. 💙", "Recovery is not a straight line. Every small step counts.", "Dr. Raahat believes in you. One breath at a time.", ], normal: [ "You're making progress every single day. 🌱", "Consistency beats intensity. You're building healthy habits.", "Your body is doing its best. Support it with rest and good food.", ], great: [ "You're thriving! Keep this momentum. 🌟", "High energy day — channel it into your health goals!", "This is what healing looks like. Celebrate the small wins.", ], }; function getAffirmation(stress: number, sleep: number): string { const pool = stress <= 3 ? AFFIRMATIONS.high_stress : stress >= 8 && sleep >= 7 ? AFFIRMATIONS.great : AFFIRMATIONS.normal; return pool[Math.floor(Math.random() * pool.length)]; } const MoodTooltip = ({ active, payload }: any) => { if (!active || !payload?.length) return null; return (
Stress: {payload[0]?.value}
Sleep: {payload[1]?.value}
); }; type Tab = "mood" | "breathe" | "history"; export default function WellnessPage() { const mentalWellness = useGUCStore((s) => s.mentalWellness); const latestReport = useGUCStore((s) => s.latestReport); const [activeTab, setActiveTab] = useState("mood"); const affirmation = getAffirmation(mentalWellness.stressLevel, mentalWellness.sleepQuality); const moodChartData = mentalWellness.moodHistory.slice(-10).map((entry) => ({ date: new Date(entry.date).toLocaleDateString("en-IN", { day: "2-digit", month: "short" }), stress: entry.stress, sleep: entry.sleep, })); const recentHistory = mentalWellness.moodHistory.slice(-7); const avgStress = recentHistory.length ? Math.round(recentHistory.reduce((s, e) => s + e.stress, 0) / recentHistory.length) : mentalWellness.stressLevel; const avgSleep = recentHistory.length ? (recentHistory.reduce((s, e) => s + e.sleep, 0) / recentHistory.length).toFixed(1) : mentalWellness.sleepQuality; const TABS: { key: Tab; label: string; icon: string }[] = [ { key: "mood", label: "Check-in", icon: "😊" }, { key: "breathe", label: "Breathe", icon: "🫁" }, { key: "history", label: "History", icon: "📈" }, ]; return ( {/* Header */}
🧘

Mental Wellness

Recovery is physical AND mental

{/* Affirmation */}

"{affirmation}"

— Dr. Raahat

{/* Stats strip */} {[ { label: "Avg Stress", value: `${avgStress}/10`, color: avgStress <= 3 ? "#EF4444" : avgStress >= 7 ? "#22C55E" : "#FF9933", icon: "🧠" }, { label: "Avg Sleep", value: `${avgSleep}/10`, color: Number(avgSleep) >= 7 ? "#22C55E" : Number(avgSleep) <= 4 ? "#EF4444" : "#FF9933", icon: "🌙" }, { label: "Streak", value: `${mentalWellness.moodHistory.length}d`, color: "#6366F1", icon: "🔥" }, ].map((stat) => (
{stat.icon}
{stat.value}
{stat.label}
))}
{/* Report mental health note */} {latestReport && mentalWellness.stressLevel <= 4 && (

🩺 Your recent report showed{" "} {latestReport.severity_level.replace("_", " ").toLowerCase()} . Medical stress is real. Talking to Dr. Raahat in the chat can help reduce anxiety about your results.

)} {/* Tabs — animated sliding indicator */}
{TABS.map((tab) => ( ))}
{/* Tab content */} {activeTab === "mood" && (

Why Sleep Matters for Recovery

{[ { icon: "🩸", text: "Iron is absorbed better when you sleep 7+ hours" }, { icon: "🦴", text: "Bone repair and Vitamin D activation happen during deep sleep" }, { icon: "🛡️", text: "Immune system strengthens during sleep cycles" }, { icon: "🧠", text: "Stress hormones drop by 30% after a full night of sleep" }, ].map((tip, i) => (
{tip.icon}

{tip.text}

))}
)} {activeTab === "breathe" && (

Why 4-7-8 Breathing Works

{[ { phase: "4", label: "Inhale", color: "#FF9933", note: "Activates parasympathetic system" }, { phase: "7", label: "Hold", color: "#6366F1", note: "Oxygen saturates bloodstream" }, { phase: "8", label: "Exhale", color: "#22C55E", note: "CO₂ released, stress drops" }, ].map((p) => (
{p.phase}s
{p.label}
{p.note}
))}

Practice 2× daily for 4 weeks to significantly reduce chronic stress

)} {activeTab === "history" && ( {moodChartData.length >= 2 ? (

Last {moodChartData.length} check-ins

Stress Sleep
} />
) : (

📊

Complete at least 2 mood check-ins to see your history chart.

Come back daily for best insights

)} {mentalWellness.moodHistory.length > 0 && (

Check-in Log

{[...mentalWellness.moodHistory].reverse().slice(0, 10).map((entry, i) => (
{new Date(entry.date).toLocaleDateString("en-IN", { day: "2-digit", month: "short" })}
= 7 ? "#22C55E" : "#FF9933" }}> 😰 {entry.stress}/10 = 7 ? "#22C55E" : entry.sleep <= 4 ? "#EF4444" : "#FF9933" }}> 🌙 {entry.sleep}/10
))}
)}
)}
); }