<?php
// public/admin/dashboard_super.php
session_start();
require_once __DIR__ . '/../../config/admin.php';
require_admin_role('SUPER_ADMIN');
require_once __DIR__ . '/../../config/db.php';

// Get stats
$total_participants = $pdo->query('SELECT COUNT(*) FROM participants')->fetchColumn();
$total_districts = $pdo->query('SELECT COUNT(*) FROM districts')->fetchColumn();
$total_blocks = $pdo->query('SELECT COUNT(*) FROM blocks')->fetchColumn();
$total_panchayats = $pdo->query('SELECT COUNT(*) FROM gps')->fetchColumn();
$selection_stats = $pdo->query('SELECT category, COUNT(*) as cnt FROM participants GROUP BY category')->fetchAll();

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Super Admin Dashboard</title>
    <link rel="stylesheet" href="/school-crm/public/assets/bootstrap.min.css">
</head>
<body>
<div class="container py-4">
    <h2 class="mb-4">Super Admin Dashboard</h2>
    <div class="row mb-4">
        <div class="col-md-3">
            <div class="card text-center">
                <div class="card-body">
                    <h5>Total Participants</h5>
                    <h2><?= $total_participants ?></h2>
                </div>
            </div>
        </div>
        <div class="col-md-3">
            <div class="card text-center">
                <div class="card-body">
                    <h5>Total Districts</h5>
                    <h2><?= $total_districts ?></h2>
                </div>
            </div>
        </div>
        <div class="col-md-3">
            <div class="card text-center">
                <div class="card-body">
                    <h5>Total Blocks</h5>
                    <h2><?= $total_blocks ?></h2>
                </div>
            </div>
        </div>
        <div class="col-md-3">
            <div class="card text-center">
                <div class="card-body">
                    <h5>Total Panchayats</h5>
                    <h2><?= $total_panchayats ?></h2>
                </div>
            </div>
        </div>
    </div>
    <div class="card mb-4">
        <div class="card-header">Selection Statistics</div>
        <div class="card-body">
            <table class="table table-bordered">
                <thead><tr><th>Category</th><th>Count</th></tr></thead>
                <tbody>
                <?php foreach ($selection_stats as $row): ?>
                    <tr><td><?= htmlspecialchars($row['category']) ?></td><td><?= $row['cnt'] ?></td></tr>
                <?php endforeach; ?>
                </tbody>
            </table>
        </div>
    </div>
    <a href="/school-crm/public/admin/admins.php" class="btn btn-primary">Manage Admins</a>
</div>
</body>
</html>
