// apps/web/src/app/(app)/admin/page.tsx // Admin CRM 대시보드 — 요약 카드 4개 import { Box, Grid } from '@mui/material' import { MetalCard, PhosphorText } from '@d3ro/ui/components/ds' import { d3roPalette } from '@d3ro/ui/theme' import { getSupabaseServerClient } from '@/lib/supabase-server' interface StatCard { label: string value: string | number color?: string } async function loadStats(): Promise { const supabase = await getSupabaseServerClient() const [profilesRes, paidRes, usageRes, expiringRes] = await Promise.all([ supabase.from('profiles').select('id', { count: 'exact', head: true }), supabase.from('subscriptions').select('id', { count: 'exact', head: true }) .neq('tier', 'free').eq('status', 'active'), supabase.from('daily_usage').select('count') .eq('date', new Date().toISOString().split('T')[0]), supabase.from('subscriptions').select('id', { count: 'exact', head: true }) .eq('status', 'active').eq('payment_provider', 'payple') .lte('current_period_end', new Date(Date.now() + 7 * 86400000).toISOString()), ]) const todayUsage = (usageRes.data as Array<{ count: number }> | null) ?.reduce((sum, r) => sum + (r.count ?? 0), 0) ?? 0 return [ { label: 'TOTAL USERS', value: profilesRes.count ?? 0 }, { label: 'PAID SUBSCRIBERS', value: paidRes.count ?? 0, color: d3roPalette.tag.green }, { label: 'TODAY API CALLS', value: todayUsage, color: d3roPalette.accent.amber }, { label: 'EXPIRING (7D)', value: expiringRes.count ?? 0, color: d3roPalette.tag.red }, ] } export default async function AdminPage(): Promise { const stats = await loadStats() return ( {stats.map((stat) => ( {stat.label} {stat.value} ))} ) }