'use client' import { useMemo } from 'react' import Link from 'next/link' import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' import type { UsageData } from '@/lib/parse-logs' import { generateCoachInsights, type CraftScores } from '@/lib/coach' import { ArrowRight, AlertTriangle, Lightbulb, Flame } from 'lucide-react' function ScoreRing({ score, size = 100 }: { score: number; size?: number }) { const radius = (size - 14) / 2 const circumference = 2 * Math.PI * radius const offset = circumference - (score / 100) * circumference const getColor = (s: number) => { if (s >= 85) return 'var(--chart-2)' if (s >= 70) return 'var(--chart-1)' if (s >= 55) return 'var(--chart-3)' return 'var(--chart-5)' } return ( {score} / 100 ) } const CRAFT_LABELS: { key: keyof CraftScores; letter: string; label: string; color: string }[] = [ { key: 'context', letter: 'C', label: 'Context', color: 'var(--chart-1)' }, { key: 'reach', letter: 'R', label: 'Reach', color: 'var(--chart-2)' }, { key: 'autonomy', letter: 'A', label: 'Autonomy', color: 'var(--chart-3)' }, { key: 'flow', letter: 'F', label: 'Flow', color: 'var(--chart-4)' }, { key: 'throughput', letter: 'T', label: 'Throughput', color: 'var(--chart-6)' }, ] function CraftBars({ craft }: { craft: CraftScores }) { return (
{CRAFT_LABELS.map(({ key, letter, label, color }) => (
{letter} {label}
{craft[key]}
))}
) } export function FitnessScore({ data }: { data: UsageData }) { const coach = useMemo(() => generateCoachInsights(data), [data]) // Pick top 2 insights: warnings first, then tips const topInsights = [ ...coach.insights.filter(i => i.severity === 'warning'), ...coach.insights.filter(i => i.severity === 'tip'), ].slice(0, 2) return (
{/* CRAFT Status — score ring + dimension bars in one card */} CRAFT Status
{coach.scoreLabel}
{coach.stats.currentStreak > 0 ? `${coach.stats.currentStreak}d streak (best: ${coach.stats.longestStreak}d)` : 'Start a streak'}
All insights
{/* Top 2 Insights */} {topInsights.map((insight, i) => ( {insight.severity === 'warning' ? <> {i === 0 ? 'Top Priority' : 'Improve'} : <> Tip} {insight.craft && ( {insight.craft} )}
{insight.title}

{insight.recommendation || insight.description}

))}
) }