'use client'; import { useEffect, useState } from 'react'; import AdminLayout from '../../components/AdminLayout'; import { getStats, getOrders } from '../../lib/api'; export default function DashboardPage() { const [stats, setStats] = useState(null); const [recentOrders, setRecentOrders] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { loadData(); }, []); const loadData = async () => { try { const [statsData, ordersData] = await Promise.all([ getStats(), getOrders(), ]); setStats(statsData); setRecentOrders(ordersData.orders?.slice(0, 5) || []); } catch (err) { console.error('Failed to load stats:', err); } finally { setLoading(false); } }; return (

Dashboard

{loading ? (

Loading...

) : ( <> {/* Stats Cards */}
{/* Order Status Breakdown */}

Orders by Status

{Object.entries(stats?.orders?.byStatus || {}).map(([status, count]) => (
{status} {count}
))}
{/* Recent Orders */}

Recent Orders

{recentOrders.length === 0 ? (

No orders yet

) : (
Order Status Amount Date
{recentOrders.map((order) => (
#{order.order_number || order.id} ${((order.total_amount || 0) / 100).toFixed(2)} {new Date(order.created_at).toLocaleDateString()}
))}
)}
)}
); } function StatCard({ label, value, color }) { return (
{label} {value}
); } function StatusBadge({ status }) { const colors = { paid: { bg: '#DBEAFE', color: '#1E40AF' }, preparing: { bg: '#FEF3C7', color: '#92400E' }, shipped: { bg: '#D1FAE5', color: '#065F46' }, delivered: { bg: '#E0E7FF', color: '#3730A3' }, installed: { bg: '#D1FAE5', color: '#065F46' }, }; const style = colors[status] || { bg: '#F3F4F6', color: '#6B7280' }; return ( {status} ); } const styles = { title: { fontSize: '24px', fontWeight: '600', marginBottom: '24px', }, loading: { color: 'var(--text-muted)', }, statsGrid: { display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: '16px', marginBottom: '32px', }, statCard: { background: 'white', padding: '20px', borderRadius: '12px', display: 'flex', flexDirection: 'column', gap: '8px', }, statLabel: { fontSize: '13px', color: 'var(--text-muted)', }, statValue: { fontSize: '28px', fontWeight: '600', }, section: { background: 'white', borderRadius: '12px', padding: '24px', marginBottom: '24px', }, sectionTitle: { fontSize: '16px', fontWeight: '600', marginBottom: '16px', }, statusGrid: { display: 'flex', gap: '24px', flexWrap: 'wrap', }, statusItem: { display: 'flex', flexDirection: 'column', gap: '4px', }, statusLabel: { fontSize: '12px', color: 'var(--text-muted)', textTransform: 'capitalize', }, statusValue: { fontSize: '20px', fontWeight: '600', }, empty: { color: 'var(--text-muted)', fontSize: '14px', }, table: { display: 'flex', flexDirection: 'column', }, tableHeader: { display: 'grid', gridTemplateColumns: '1fr 1fr 1fr 1fr', gap: '16px', padding: '12px 0', borderBottom: '1px solid var(--border)', fontSize: '12px', fontWeight: '600', color: 'var(--text-muted)', textTransform: 'uppercase', }, tableRow: { display: 'grid', gridTemplateColumns: '1fr 1fr 1fr 1fr', gap: '16px', padding: '16px 0', borderBottom: '1px solid var(--border)', alignItems: 'center', fontSize: '14px', }, orderId: { fontWeight: '500', }, date: { color: 'var(--text-muted)', }, };