'use client'; import React from 'react'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import { Progress } from '@/components/ui/progress'; import { Link, Link2Off, TrendingUp, TrendingDown, Moon, Utensils, Baby, Activity, Info, CheckCircle, } from 'lucide-react'; import { CorrelationAnalysis } from '@/lib/api/analytics'; interface CorrelationInsightsProps { data: CorrelationAnalysis | null; loading?: boolean; error?: Error | null; } export function CorrelationInsights({ data, loading, error }: CorrelationInsightsProps) { if (loading) { return (
Analyzing activity correlations...
); } if (error) { return ( Error loading correlation data ); } if (!data) { return null; } const getCorrelationStrength = (value: number) => { const absValue = Math.abs(value); if (absValue > 0.7) return 'Strong'; if (absValue > 0.4) return 'Moderate'; if (absValue > 0.2) return 'Weak'; return 'Negligible'; }; const getCorrelationColor = (value: number) => { const absValue = Math.abs(value); if (absValue > 0.7) return 'bg-purple-100 text-purple-800'; if (absValue > 0.4) return 'bg-blue-100 text-blue-800'; if (absValue > 0.2) return 'bg-gray-100 text-gray-800'; return 'bg-gray-50 text-gray-600'; }; const getCorrelationIcon = (value: number) => { if (value > 0.3) return ; if (value < -0.3) return ; return ; }; const formatCorrelation = (value: number) => { return (value * 100).toFixed(0) + '%'; }; const correlations = [ { name: 'Feeding & Sleep', value: data.feedingSleepCorrelation, icon1: , icon2: , description: data.feedingSleepCorrelation > 0 ? 'Better feeding patterns correlate with better sleep' : data.feedingSleepCorrelation < 0 ? 'More feedings may be disrupting sleep patterns' : 'No significant relationship detected', }, { name: 'Activity & Diapers', value: data.activityDiaperCorrelation, icon1: , icon2: , description: data.activityDiaperCorrelation > 0 ? 'More activity correlates with more diaper changes' : data.activityDiaperCorrelation < 0 ? 'Less active periods show more diaper changes' : 'No clear pattern between activity and diapers', }, ...(data.sleepMoodCorrelation !== undefined ? [{ name: 'Sleep & Mood', value: data.sleepMoodCorrelation, icon1: , icon2: , description: data.sleepMoodCorrelation > 0 ? 'Better sleep strongly correlates with better mood' : data.sleepMoodCorrelation < 0 ? 'Sleep patterns inversely affect mood' : 'Sleep and mood appear independent', }] : []), ]; return ( Activity Correlations {/* Correlation Visualizations */}
{correlations.map((correlation) => (
{correlation.icon1} & {correlation.icon2}
{correlation.name}
{getCorrelationIcon(correlation.value)} {getCorrelationStrength(correlation.value)}
{/* Correlation Bar */}
0 ? '50%' : `${50 + correlation.value * 50}%`, width: `${Math.abs(correlation.value) * 50}%`, }} >
0 ? 'bg-green-500' : 'bg-red-500' }`} style={{ width: '100%' }} />
0 ? `${50 + correlation.value * 50}%` : '50%', transform: correlation.value > 0 ? 'translateX(-100%)' : 'none', }} > {formatCorrelation(correlation.value)}

{correlation.description}

))}
{/* Correlation Scale Legend */}

Correlation Scale

Positive: Activities increase together
Negative: One increases, other decreases
{/* Insights */} {data.insights.length > 0 && (

Key Insights

{data.insights.map((insight, index) => (

{insight}

))}
)} ); }