import { redirect } from "next/navigation"; import Link from "next/link"; import { getCurrentUser } from "@/lib/auth"; import { getWeeklyWorkoutCount, getMonthlyWorkoutCount, getYearlyWorkoutCount, getWeeklyVolume, } from "@/lib/db/stats"; import { getRecentWorkouts } from "@/lib/db/workouts"; import { ActivitySquare, Calendar, CalendarDays, History, Plus } from "lucide-react"; export default async function DashboardPage() { const user = await getCurrentUser(); if (!user) { redirect("/auth/login"); } const [weeklyCount, monthlyCount, yearlyCount, _weeklyVolume, recentWorkouts] = await Promise.all([ getWeeklyWorkoutCount(user.id), getMonthlyWorkoutCount(user.id), getYearlyWorkoutCount(user.id), getWeeklyVolume(user.id), getRecentWorkouts(user.id, 5), ]); return (
{/* Header with greeting */}

Welcome back, {user.name || "Trainer"}!

Keep pushing your limits and achieving your goals.

{/* Main content */}
{/* Stats Cards */}
{/* This Week */}

This Week

{weeklyCount}

workouts

{/* This Month */}

This Month

{monthlyCount}

workouts

{/* This Year */}

This Year

{yearlyCount}

workouts

{/* Quick Actions */}
Log Workout View History
{/* Recent Workouts */}

Recent Workouts

{recentWorkouts.length === 0 ? (

No workouts yet

Start your fitness journey by logging your first workout!

Log First Workout
) : (
{recentWorkouts.map((workout) => (

{workout.name || "Unnamed Workout"}

{new Date(workout.date).toLocaleDateString("en-US", { weekday: "short", month: "short", day: "numeric", year: "numeric", })}

{(workout as any).setLogs.length} sets {workout.durationMinutes && ` ยท ${workout.durationMinutes} min`}

{(workout as any).setLogs.length}

{(workout as any).setLogs.length === 1 ? "set" : "sets"}

))}
)}
); }