'use client'; import React from 'react'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Progress } from '@/components/ui/progress'; import { Badge } from '@/components/ui/badge'; import { Moon, Sun, Clock, Brain, AlertCircle, CheckCircle2 } from 'lucide-react'; import { CircadianRhythm } from '@/lib/api/analytics'; interface CircadianRhythmCardProps { data: CircadianRhythm | null; loading?: boolean; error?: Error | null; } export function CircadianRhythmCard({ data, loading, error }: CircadianRhythmCardProps) { if (loading) { return (
Loading circadian rhythm analysis...
); } if (error) { return ( Error loading circadian rhythm data ); } if (!data) { return null; } const getChronotypeIcon = () => { switch (data.chronotype) { case 'early_bird': return ; case 'night_owl': return ; default: return ; } }; const getChronotypeColor = () => { switch (data.chronotype) { case 'early_bird': return 'bg-yellow-100 text-yellow-800'; case 'night_owl': return 'bg-indigo-100 text-indigo-800'; default: return 'bg-gray-100 text-gray-800'; } }; const formatTime = (time: string) => { // Convert HH:MM to 12-hour format const [hours, minutes] = time.split(':'); const hour = parseInt(hours); const ampm = hour >= 12 ? 'PM' : 'AM'; const displayHour = hour === 0 ? 12 : hour > 12 ? hour - 12 : hour; return `${displayHour}:${minutes} ${ampm}`; }; return ( Circadian Rhythm Analysis {getChronotypeIcon()} {data.chronotype.replace('_', ' ')} {/* Sleep Consistency Score */}
Sleep Consistency {Math.round(data.consistency * 100)}%

{data.consistency > 0.8 ? 'Excellent - Very consistent sleep schedule' : data.consistency > 0.6 ? 'Good - Fairly consistent schedule' : 'Needs improvement - Irregular sleep pattern'}

{/* Optimal Times */}
Optimal Bedtime

{formatTime(data.optimalBedtime)}

Optimal Wake Time

{formatTime(data.optimalWakeTime)}

{/* Sleep Phase Shift */}
Sleep Phase Shift {data.sleepPhaseShift > 0 ? '+' : ''}{data.sleepPhaseShift.toFixed(1)} hours
{Math.abs(data.sleepPhaseShift) < 1 ? ( ) : ( )}

{Math.abs(data.sleepPhaseShift) < 1 ? 'Sleep schedule aligned with typical patterns' : data.sleepPhaseShift > 0 ? `Bedtime is ${Math.abs(data.sleepPhaseShift).toFixed(1)} hours later than typical` : `Bedtime is ${Math.abs(data.sleepPhaseShift).toFixed(1)} hours earlier than typical`}

{/* Melatonin Onset */}
Estimated Melatonin Onset

{formatTime(data.melatoninOnset)}

Natural sleepiness begins around this time

{/* Recommended Schedule */}

Recommended Daily Schedule

Wake Time {formatTime(data.recommendedSchedule.wakeTime)}
{data.recommendedSchedule.morningNap && (
Morning Nap {formatTime(data.recommendedSchedule.morningNap.start)} ({data.recommendedSchedule.morningNap.duration} min)
)} {data.recommendedSchedule.afternoonNap && (
Afternoon Nap {formatTime(data.recommendedSchedule.afternoonNap.start)} ({data.recommendedSchedule.afternoonNap.duration} min)
)}
Bedtime {formatTime(data.recommendedSchedule.bedtime)}
Daily Sleep Target {Math.round(data.recommendedSchedule.totalSleepTarget / 60)} hours
); }