<?php
session_start();
if (!isset($_SESSION['admin'])) {
    header("Location: auth/login.php");
    exit;
}

include("config/db.php");

// Counts
$districts = $conn->query("SELECT COUNT(*) as total FROM districts")->fetch_assoc()['total'];
$blocks = $conn->query("SELECT COUNT(*) as total FROM blocks")->fetch_assoc()['total'];
$villages = $conn->query("SELECT COUNT(*) as total FROM villages")->fetch_assoc()['total'];
?>

<?php include("includes/header.php"); ?>
<?php include("includes/sidebar.php"); ?>

<style>
.card-box {
    border-radius: 15px;
    padding: 20px;
    color: white;
    box-shadow: 0 8px 20px rgba(0,0,0,0.1);
}
.bg-blue { background: linear-gradient(135deg, #36d1dc, #5b86e5); }
.bg-green { background: linear-gradient(135deg, #56ab2f, #a8e063); }
.bg-orange { background: linear-gradient(135deg, #ff8008, #ffc837); }

.topbar {
    background: white;
    padding: 15px 20px;
    border-radius: 10px;
    margin-bottom: 20px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.05);
}
</style>

<!-- Topbar -->
<div class="topbar d-flex justify-content-between align-items-center">
    <h4>Dashboard</h4>
    <div>Welcome, <b><?= $_SESSION['admin'] ?></b></div>
</div>

<!-- Cards -->
<div class="row">

    <div class="col-md-4">
        <div class="card-box bg-blue">
            <h5>Total Districts</h5>
            <h2><?= $districts ?></h2>
        </div>
    </div>

    <div class="col-md-4">
        <div class="card-box bg-green">
            <h5>Total Blocks</h5>
            <h2><?= $blocks ?></h2>
        </div>
    </div>

    <div class="col-md-4">
        <div class="card-box bg-orange">
            <h5>Total Villages</h5>
            <h2><?= $villages ?></h2>
        </div>
    </div>

</div>

<br>

<!-- Quick Actions -->
<div class="card p-4">
    <h5>Quick Actions</h5>
    <hr>

    <a href="districts/index.php" class="btn btn-primary me-2">Manage Districts</a>
    <a href="blocks/index.php" class="btn btn-success me-2">Manage Blocks</a>
    <a href="villages/index.php" class="btn btn-warning">Manage Villages</a>
</div>

<?php include("includes/footer.php"); ?>