'use client'; import { Card, CardContent, Typography, Box, Chip, LinearProgress, Stack, Alert } from '@mui/material'; import { TrendingUp, Hotel, Restaurant, AccessTime, WbSunny } from '@mui/icons-material'; import { formatDistanceToNow, format } from 'date-fns'; import { PredictionInsights } from '@/lib/api/analytics'; import { useLocalizedDate } from '@/hooks/useLocalizedDate'; interface PredictionsCardProps { predictions: PredictionInsights | null; loading: boolean; } export default function PredictionsCard({ predictions, loading }: PredictionsCardProps) { const { formatDistance } = useLocalizedDate(); if (loading) { return ( Predictions ); } if (!predictions) { return ( Predictions Not enough data for predictions yet. Track more activities to see predictions! ); } const { sleep, feeding } = predictions; // Calculate confidence color const getConfidenceColor = (confidence: number): string => { if (confidence >= 0.85) return 'success'; if (confidence >= 0.6) return 'warning'; return 'error'; }; // Format confidence percentage const formatConfidence = (confidence: number): string => { return `${Math.round(confidence * 100)}%`; }; return ( Predictions Updated {formatDistanceToNow(predictions.generatedAt, { addSuffix: true })} {/* Sleep Predictions */} Sleep {sleep.nextNapTime ? ( Next Nap {formatDistanceToNow(sleep.nextNapTime, { addSuffix: true })} ({format(sleep.nextNapTime, 'h:mm a')}) ) : ( No nap prediction available )} {sleep.nextBedtime && ( Next Bedtime {formatDistanceToNow(sleep.nextBedtime, { addSuffix: true })} ({format(sleep.nextBedtime, 'h:mm a')}) )} {sleep.optimalWakeWindows.length > 0 && ( Optimal wake windows: {sleep.optimalWakeWindows.map((w) => `${w} min`).join(', ')} )} {sleep.reasoning && ( {sleep.reasoning} )} {/* Feeding Predictions */} Feeding {feeding.nextFeedingTime ? ( Next Feeding {formatDistanceToNow(feeding.nextFeedingTime, { addSuffix: true })} ({format(feeding.nextFeedingTime, 'h:mm a')}) Expected interval: {feeding.expectedInterval.toFixed(1)} hours ) : ( No feeding prediction available )} {feeding.reasoning && ( {feeding.reasoning} )} ); }