import { createClient } from '@/lib/supabase/server' import { createAdminClient } from '@/lib/supabase/admin' 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 adminDb = createAdminClient() const [ { data: orders }, { count: userCount }, { count: productCount }, ] = await Promise.all([ adminDb.from('orders').select('total_price, status, created_at'), adminDb.from('profiles').select('*', { count: 'exact', head: true }), supabase.from('products').select('*', { count: 'exact', head: true }), ]) const now = new Date() const currentYear = now.getFullYear() const currentMonth = now.getMonth() const completedOrdersThisMonth = (orders ?? []).filter(o => { if (o.status !== 'completed') return false const orderDate = new Date(o.created_at) return orderDate.getFullYear() === currentYear && orderDate.getMonth() === currentMonth }) const totalRevenue = completedOrdersThisMonth.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 aktueller Monat
{new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(totalRevenue)}

Nur fertige Bestellungen

Bestellungen
{orderCount}

Gesamt

Produkte
{productCount}

Im Katalog

Kunden
{userCount}

Registrierte User

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