"use client"; import { useEffect, useState } from "react"; import Link from "next/link"; import { AuthGuard } from "@/components/auth/AuthGuard"; import { Navbar } from "@/components/layout/Navbar"; import { BottomNav } from "@/components/layout/BottomNav"; import { SupersetCard } from "@/components/workout/SupersetCard"; import { Spinner } from "@/components/ui/Spinner"; import { api } from "@/lib/api"; import type { WorkoutDetail } from "@/lib/types"; function formatTime(seconds: number | null): string { if (!seconds) return "N/A"; const mins = Math.round(seconds / 60); if (mins >= 60) { const h = Math.floor(mins / 60); const m = mins % 60; return m > 0 ? `${h}h ${m}m` : `${h}h`; } return `${mins}m`; } export default function WorkoutDetailPage({ params, }: { params: { workoutId: string }; }) { const { workoutId } = params; const [workout, setWorkout] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { api .getWorkoutDetail(Number(workoutId)) .then(setWorkout) .catch((err) => console.error("Failed to fetch workout:", err)) .finally(() => setLoading(false)); }, [workoutId]); return (
Back {loading ? (
) : !workout ? (

Workout not found.

) : (

{workout.name}

{workout.description && (

{workout.description}

)}
{formatTime(workout.estimated_time)} {workout.supersets.length} superset {workout.supersets.length !== 1 ? "s" : ""}
{[...workout.supersets] .sort((a, b) => a.order - b.order) .map((superset, i) => ( ))}
)}
); }