<?php
// ==============================
// PROTECT HALAMAN ADMIN
// ==============================
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

if (!isset($_SESSION['user'])) {
    header("Location: /presensi_v1/auth/login.php");
    exit;
}

// ROLE HARUS superadmin ATAU operator
$role = $_SESSION['user']['role'];

if (!in_array($role, ['superadmin', 'operator'])) {
    header("Location: /presensi_v1/preview.php");
    exit;
}
?>
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<title>Dashboard - Admin</title>
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- Bootstrap -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css" rel="stylesheet">

<!-- Font -->
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap" rel="stylesheet">

<!-- Custom CSS -->
<link rel="stylesheet" href="/presensi_v1/assets/css/style.css">

<!-- SweetAlert2 -->
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
</head>

<script>
function updateLiveClock() {
    const el = document.getElementById("nav-live-clock");
    if (!el) return;

    const now = new Date();
    el.innerText = now.toLocaleTimeString("id-ID", {
        hour: "2-digit",
        minute: "2-digit",
        second: "2-digit"
    }) + " WIB";
}

document.addEventListener("DOMContentLoaded", () => {
    updateLiveClock();
    setInterval(updateLiveClock, 1000);
});
</script>

<body>

<!-- ============================== -->
<!-- TOP NAVBAR -->
<!-- ============================== -->
<nav class="navbar matrix-header shadow-sm">
    <div class="container-fluid d-flex justify-content-between align-items-center">

        <!-- LEFT -->
        <div class="d-flex align-items-center">
            <button class="btn btn-sm btn-dark me-3" id="sidebarToggle">
                <i class="bi bi-list"></i>
            </button>

            <span class="matrix-brand">Presensi <span class="brand-light">V1</span></span>
        </div>

        <!-- RIGHT -->
        <div class="d-flex align-items-center gap-3">
            <div class="text-white fw-bold" id="nav-live-clock">00:00:00</div>

            <!-- ROLE DINAMIS -->
            <span class="text-white fw-semibold text-capitalize">
                <?= htmlspecialchars($role) ?>
            </span>

            <a href="/presensi_v1/auth/logout.php" class="btn btn-danger btn-sm">
                Logout
            </a>
        </div>

    </div>
</nav>

<!-- ============================== -->
<!-- SIDEBAR -->
<!-- ============================== -->
<div id="matrixSidebar" class="matrix-sidebar">
    <ul class="matrix-menu">

        <li>
            <a href="/presensi_v1/pages/dashboard.php">
                <i class="bi bi-graph-up"></i>
                <span>Dashboard</span>
            </a>
        </li>

        <li>
            <a href="/presensi_v1/pages/manage_siswa.php">
                <i class="bi bi-people"></i>
                <span>Kelola Siswa</span>
            </a>
        </li>

        <li>
            <a href="/presensi_v1/pages/manage_uid.php">
                <i class="bi bi-upc-scan"></i>
                <span>Kelola UID</span>
            </a>
        </li>

        <li>
            <a href="/presensi_v1/pages/settings.php">
                <i class="bi bi-alarm"></i>
                <span>Pengaturan</span>
            </a>
        </li>

        <li>
            <a href="/presensi_v1/pages/rekap.php">
                <i class="bi bi-person-vcard-fill"></i>
                <span>Log Presensi</span>
            </a>
        </li>

        <li>
            <a href="/presensi_v1/pages/users.php">
                <i class="bi bi-person-circle"></i>
                <span>Users</span>
            </a>
        </li>

    </ul>
</div> <!-- END SIDEBAR -->

<!-- ============================== -->
<!-- MAIN CONTENT WRAPPER -->
<!-- ============================== -->
<div class="matrix-content">
