import { useState } from 'react'; import { ChevronDown, ChevronUp, TrendingDown, TrendingUp } from 'lucide-react'; import { Bar, BarChart, CartesianGrid, Line, LineChart, ResponsiveContainer, Tooltip, XAxis, YAxis, } from 'recharts'; import type { ExerciseProgress } from '../api/types'; import { fmtDate, fmtVolume } from '../lib/format'; import { MUSCLE_NAMES } from '../lib/labels'; import { Badge, Tabs } from './ui'; const TOOLTIP_STYLE = { background: 'var(--bg-card)', border: '1px solid var(--border)', borderRadius: 12, color: 'var(--text)', }; /** * Lista postępów per ćwiczenie: wiersz (nazwa + 1RM + delta + objętość + PR), * tap rozwija kartę z zakładkami 1RM/Objętość i jednym wykresem (renderowany * tylko dla aktywnej zakładki — unik ostrzeżeń recharts/ResizeObserver). * Współdzielone z detalem podopiecznego (spójnie). */ export default function ExerciseProgressCards({ exercises }: { exercises: ExerciseProgress[] }) { const [openId, setOpenId] = useState(null); // aktywna zakładka per ćwiczenie (domyślnie 1RM) const [tabs, setTabs] = useState>({}); return (
{exercises.map((ex) => { const last = ex.points[ex.points.length - 1]; const prev = ex.points[ex.points.length - 2]; const oneRmDelta = last?.oneRm != null && prev?.oneRm != null ? last.oneRm - prev.oneRm : null; const maxOneRm = ex.points.reduce( (max, p) => (p.oneRm != null && p.oneRm > max ? p.oneRm : max), 0, ); const isPr = last?.oneRm != null && last.oneRm === maxOneRm && ex.points.length > 1; const open = openId === ex.exerciseId; const tab = tabs[ex.exerciseId] ?? 'onerm'; const setTab = (t: 'onerm' | 'volume') => setTabs((m) => ({ ...m, [ex.exerciseId]: t })); return (
{/* Wiersz: nazwa + mięsień (meta) + 1RM + delta + objętość + PR */} {/* Rozwinięta karta: zakładki 1RM/Objętość + jeden wykres */} {open && (
setTab(id as 'onerm' | 'volume')} /> {tab === 'onerm' ? : }
)}
); })}
); } function OneRmChart({ ex }: { ex: ExerciseProgress }) { const oneRmPoints = ex.points.filter((p) => p.oneRm != null); if (oneRmPoints.length < 2) { return (

Za mało danych na wykres 1RM (min. 2 sesje).

); } return (
({ date: fmtDate(p.date), oneRm: p.oneRm }))}>
); } function VolumeChart({ ex }: { ex: ExerciseProgress }) { const volumePoints = ex.points.filter((p) => p.volumeKg != null); if (volumePoints.length < 1) { return (

Brak danych o objętości (serie bez obciążenia).

); } return (
({ date: fmtDate(p.date), volumeKg: p.volumeKg }))}>
); }