import { createClient } from '@/lib/supabase/server' import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' import { Package, ShoppingCart, Users, TrendingUp } from 'lucide-react' import { AdminRecentOrders } from '@/components/admin/recent-orders' // ─── KPI-Daten aus DB ──────────────────────────────────────────────────────── async function getKpis() { const supabase = await createClient() const [ { data: orders }, { count: userCount }, { count: productCount }, ] = await Promise.all([ supabase.from('orders').select('total_price, status'), supabase.from('profiles').select('*', { count: 'exact', head: true }), supabase.from('products').select('*', { count: 'exact', head: true }), ]) const totalRevenue = (orders ?? []).reduce((sum, o) => sum + Number(o.total_price), 0) const orderCount = (orders ?? []).length return { totalRevenue, orderCount, userCount: userCount ?? 0, productCount: productCount ?? 0 } } export default async function AdminDashboard() { const { totalRevenue, orderCount, userCount, productCount } = await getKpis() return (

Dashboard

{/* KPI Cards – echte DB-Daten */}
Umsatz gesamt
{new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(totalRevenue)}

Aus allen Bestellungen

Bestellungen
{orderCount}

Gesamt

Produkte
{productCount}

Im Katalog

Kunden
{userCount}

Registrierte User

{/* Letzte Bestellungen – Client Component mit 30s-Polling */}
) }