<?php
session_start();
if (!isset($_SESSION['id_admin'])) {
    header('Location: login_admin.php');
    exit;
}
include 'includes/config.php';

// Ambil maklumat admin dari session
$nama_admin = $_SESSION['nama'] ?? 'Admin';
$tarikh = date("d/m/Y");

// Statistik ringkas
$total_pelajar = mysqli_fetch_assoc(mysqli_query($conn, "SELECT COUNT(*) AS jumlah FROM pelajar"))['jumlah'];
$total_aktiviti = mysqli_fetch_assoc(mysqli_query($conn, "SELECT COUNT(*) AS jumlah FROM aktiviti"))['jumlah'];
$total_penyertaan = mysqli_fetch_assoc(mysqli_query($conn, "SELECT COUNT(*) AS jumlah FROM penyertaan"))['jumlah'];
?>
<!DOCTYPE html>
<html lang="ms">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Dashboard Admin - e-SPEKTRA</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css" rel="stylesheet">
<style>
body {
    background-color: #f4f6f9;
}
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: 220px;
    background: linear-gradient(180deg, #3b0a77, #ff6f00);
    color: white;
    padding-top: 100px;
}
.sidebar a {
    display: block;
    padding: 12px 20px;
    color: white;
    text-decoration: none;
    font-weight: 500;
}
.sidebar a:hover {
    background: rgba(255,255,255,0.1);
}
.header-main {
    position: fixed;
    top: 0;
    left: 220px;
    right: 0;
    height: 100px;
    background: linear-gradient(90deg, #3b0a77, #ff6f00);
    color: white;
    padding: 20px 30px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    z-index: 1030;
}
.content {
    margin-left: 220px;
    margin-top: 100px;
    padding: 20px;
}
.stat-box {
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
    text-align: center;
}
.stat-box h3 {
    font-size: 28px;
    margin: 0;
}
</style>
</head>
<body>

<!-- SIDEBAR -->
<div class="sidebar">
    <a href="dashboard_admin.php"><i class="bi bi-speedometer2"></i> Dashboard</a>
    <a href="senarai_aktiviti.php"><i class="bi bi-calendar-event"></i> Pengurusan Aktiviti</a>
    <a href="senarai_pelajar.php"><i class="bi bi-people"></i> Pengurusan Pelajar</a>
    <a href="laporan.php"><i class="bi bi-bar-chart"></i> Laporan & Statistik</a>
    <a href="tetapan.php"><i class="bi bi-gear"></i> Tetapan Sistem</a>
    <a href="logout.php" onclick="return confirm('Log keluar?')"><i class="bi bi-box-arrow-right"></i> Log Keluar</a>
</div>

<!-- HEADER -->
<div class="header-main d-flex justify-content-between align-items-center">
    <div>
        <h2 style="margin:0;">e-SPEKTRA - Dashboard Admin</h2>
        <small>Tarikh: <?= $tarikh ?></small>
    </div>
    <div>
        <i class="bi bi-person-circle"></i> <?= htmlspecialchars($nama_admin) ?>
    </div>
</div>

<!-- CONTENT -->
<div class="content">
    <h3>Selamat Datang, <?= htmlspecialchars($nama_admin) ?>!</h3>
    <p>Berikut adalah ringkasan statistik sistem:</p>

    <div class="row g-3">
        <div class="col-md-4">
            <div class="stat-box">
                <i class="bi bi-people" style="font-size:40px;color:#3b0a77;"></i>
                <h3><?= $total_pelajar ?></h3>
                <p>Jumlah Pelajar</p>
            </div>
        </div>
        <div class="col-md-4">
            <div class="stat-box">
                <i class="bi bi-calendar-event" style="font-size:40px;color:#ff6f00;"></i>
                <h3><?= $total_aktiviti ?></h3>
                <p>Jumlah Aktiviti</p>
            </div>
        </div>
        <div class="col-md-4">
            <div class="stat-box">
                <i class="bi bi-check2-circle" style="font-size:40px;color:green;"></i>
                <h3><?= $total_penyertaan ?></h3>
                <p>Jumlah Penyertaan</p>
            </div>
        </div>
    </div>
</div>

</body>
</html>
