<?php
require_once __DIR__ . '/../config.php';
requireRole(['admin', 'manager']);

$pageTitle = 'Admin Dashboard';
require_once __DIR__ . '/../includes/admin-header.php';

require_once __DIR__ . '/../lib/logic.php';
$kpis = getDashboardKPIs();

$pdo = getDBConnection();
$allUsers = $pdo->query("SELECT * FROM users ORDER BY created_at DESC")->fetchAll();
?>

        <div class="row g-4 mb-4">
            <div class="col-md-3">
                <div class="card stat-card primary">
                    <div class="card-body">
                        <div class="text-muted">Total Orders</div>
                        <div class="stat-value"><?php echo number_format($kpis['total_orders']); ?></div>
                    </div>
                </div>
            </div>
            <div class="col-md-3">
                <div class="card stat-card success">
                    <div class="card-body">
                        <div class="text-muted">Total Items</div>
                        <div class="stat-value"><?php echo number_format($kpis['total_items']); ?></div>
                    </div>
                </div>
            </div>
            <div class="col-md-3">
                <div class="card stat-card warning">
                    <div class="card-body">
                        <div class="text-muted">Total Suppliers</div>
                        <div class="stat-value"><?php echo number_format($kpis['total_suppliers']); ?></div>
                    </div>
                </div>
            </div>
            <div class="col-md-3">
                <div class="card stat-card danger">
                    <div class="card-body">
                        <div class="text-muted">Total Users</div>
                        <div class="stat-value"><?php echo count($allUsers); ?></div>
                    </div>
                </div>
            </div>
        </div>

<?php require_once __DIR__ . '/../includes/admin-footer.php';
