import { notFound } from "next/navigation"; import { AiAnalysisCard } from "@/components/ai-analysis-card"; import { ExerciseProgressChart } from "@/components/exercise-progress-chart"; import { InfoTooltip } from "@/components/info-tooltip"; import { formatDate, formatDateShort } from "@/lib/format"; import { getLatestAnalysisForTarget, serializeAnalysis } from "@/lib/models/analysis"; import { getStrengthWorkout, listStrengthWorkouts } from "@/lib/models/strength"; import { exerciseE1rm, getExerciseHistory } from "@/lib/strength/stats"; import { getCurrentUserId } from "@/lib/session"; export const dynamic = "force-dynamic"; const EXERCISE_HISTORY_LIMIT = 8; export default async function StrengthWorkoutPage({ params, }: { params: Promise<{ id: string }>; }) { const { id } = await params; const userId = await getCurrentUserId(); const workout = await getStrengthWorkout(userId, id); if (!workout) { notFound(); } const analysis = await getLatestAnalysisForTarget(userId, "strength", workout._id); const allWorkouts = await listStrengthWorkouts(userId); const pastWorkouts = allWorkouts.filter((w) => w.date <= workout.date); const exercisesWithHistory = workout.exercises.map((exercise) => ({ exercise, history: getExerciseHistory(exercise.name, pastWorkouts, EXERCISE_HISTORY_LIMIT), })); return (

{workout.name}

{formatDate(workout.date)}

{workout.notes ?

{workout.notes}

: null}
{exercisesWithHistory.map(({ exercise }, index) => { const e1rm = exerciseE1rm(exercise); return (

{exercise.name}

{exercise.notes ?

{exercise.notes}

: null}
{exercise.sets.map((set) => { const pct = e1rm && set.weightKg != null ? Math.round((set.weightKg / e1rm) * 100) : null; return ( {set.reps ?? "?"}×{set.weightKg !== undefined ? `${set.weightKg} kg` : "—"} {pct !== null ? ( {pct}% ) : null} ); })}
); })}
{exercisesWithHistory.some(({ history }) => history.length >= 2) ? (

Postęp ćwiczeń

{exercisesWithHistory .filter(({ history }) => history.length >= 2) .map(({ exercise, history }) => ( ({ label: formatDateShort(point.date), volumeKg: point.volumeKg, topWeightKg: point.topWeightKg, e1rmKg: point.e1rmKg, }))} /> ))}
) : null} {workout.sourceUrl ? ( {workout.sourceUrl} ) : null}
); }