<?php
include '../config.php';

if (!isAdmin()) {
    redirect('../login.php');
}

// Ambil statistik
$sql_stats = "SELECT 
    (SELECT COUNT(*) FROM lms_users WHERE role = 'siswa') as total_siswa,
    (SELECT COUNT(*) FROM lms_users WHERE role = 'guru') as total_guru,
    (SELECT COUNT(*) FROM lms_courses) as total_lms_courses,
    (SELECT COUNT(*) FROM lms_enrollments) as total_lms_enrollments";
$stats = $conn->query($sql_stats)->fetch_assoc();
?>

<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dashboard Admin - SMANSAB LMS</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
</head>
<body>
    <!-- Navbar Admin -->
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
        <div class="container">
            <a class="navbar-brand fw-bold bi bi-book-half" href="dashboard.php"> SMANSAB LMS - Admin</a>
            <div class="navbar-nav ms-auto">
                <a class="nav-link" href="manage_users.php">Kelola User</a>
                <a class="nav-link" href="manage_courses.php">Kelola Kursus</a>
                <a class="nav-link" href="../logout.php">Logout</a>
            </div>
        </div>
    </nav>

    <div class="container mt-4">
        <h2>Dashboard Admin</h2>
        
        <!-- Statistik -->
        <div class="row mt-4">
            <div class="col-md-3">
                <div class="card bg-primary text-white">
                    <div class="card-body">
                        <h5><i class="bi bi-people"></i> Total Siswa</h5>
                        <h3><?php echo $stats['total_siswa']; ?></h3>
                    </div>
                </div>
            </div>
            <div class="col-md-3">
                <div class="card bg-success text-white">
                    <div class="card-body">
                        <h5><i class="bi bi-person-badge"></i> Total Guru</h5>
                        <h3><?php echo $stats['total_guru']; ?></h3>
                    </div>
                </div>
            </div>
            <div class="col-md-3">
                <div class="card bg-warning text-dark">
                    <div class="card-body">
                        <h5><i class="bi bi-book"></i> Total Kursus</h5>
                        <h3><?php echo $stats['total_lms_courses']; ?></h3>
                    </div>
                </div>
            </div>
            <div class="col-md-3">
                <div class="card bg-info text-white">
                    <div class="card-body">
                        <h5><i class="bi bi-graph-up"></i> Total Enroll</h5>
                        <h3><?php echo $stats['total_lms_enrollments']; ?></h3>
                    </div>
                </div>
            </div>
        </div>

        <!-- Quick Actions -->
        <div class="row mt-5">
            <div class="col-12">
                <h4 align="center">Quick Actions</h4>
                <div class="d-grid gap-2 d-md-flex justify-content-center text-center">
                    <a href="manage_users.php" class="btn btn-primary me-2">Kelola User</a>
                    <a href="manage_courses.php" class="btn btn-success me-2">Kelola Kursus</a>
                    <a href="reports.php" class="btn btn-info">Lihat Laporan</a>
                </div>
            </div>
        </div>
    </div>
</body>
</html>