import { auth } from "@/lib/auth"; import { redirect } from "next/navigation"; import { getDashboardStats } from "@/data/dashboard.queries"; import { getUserSettings } from "@/data/settings.queries"; import { Package, DollarSign, AlertTriangle, Activity } from "lucide-react"; import { StatCard } from "@/components/shared/stat-card"; import { ColorSwatch } from "@/components/shared/color-swatch"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; export default async function DashboardPage() { const session = await auth(); if (!session?.user?.id) redirect("/login"); const settings = await getUserSettings(session.user.id); const stats = await getDashboardStats(session.user.id, settings.lowStockThreshold); const currencyFormatter = new Intl.NumberFormat("en-US", { style: "currency", currency: settings.currency, }); return (
{/* Stats Grid */}
0 ? "text-orange-400" : undefined} />
{/* Low Stock Alerts */} Low Stock Alerts Items below {settings.lowStockThreshold}% remaining {stats.lowStockItems.length === 0 ? (

All items are well stocked.

) : (
{stats.lowStockItems.map((item) => (

{item.name}

{item.type}

{Math.round(item.remaining)} {item.type === "filament" ? "g" : "ml"}

{Math.round(item.percent)}% left

))}
)}
{/* Recent Usage */} Recent Usage Latest consumption log entries {stats.recentUsage.length === 0 ? (

No usage logged yet.

) : (
{stats.recentUsage.map((log) => (
{log.itemType}

{log.itemName}

{log.notes || "No notes"}

-{log.amount}{log.unit}

{new Date(log.createdAt).toLocaleDateString()}

))}
)}
); }