<?php
session_start();
require_once __DIR__ . '/config/config.php';

if (!isset($_SESSION['id_user'])) {
    header("Location: index.php");
    exit;
}

$nama_lengkap = $_SESSION['nama_lengkap'] ?? 'User';
$role = $_SESSION['role'] ?? '-';
?>
<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <title>Dashboard e-BOS</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">

    <style>
        body {
            margin: 0;
            overflow-x: hidden;
            background-color: #f4f6f9;
        }

        /* NAVBAR */
        .navbar {
            height: 56px;
        }

        /* SIDEBAR */
        .sidebar {
            position: fixed;
            top: 56px;
            left: 0;
            width: 240px;
            height: calc(100vh - 56px);
            background: #0d6efd; /* biru seperti app guru */
            color: #fff;
            overflow-y: auto;
        }

        .sidebar .title {
            font-weight: bold;
            padding: 15px;
            font-size: 15px;
            background: #0b5ed7;
            text-align: center;
        }

        .sidebar ul {
            list-style: none;
            padding: 0;
            margin: 0;
        }

        .sidebar ul li a {
            display: flex;
            align-items: center;
            gap: 10px;
            padding: 12px 18px;
            color: #eaeaea;
            text-decoration: none;
            font-size: 14px;
            transition: 0.2s;
        }

        .sidebar ul li a:hover {
            background: rgba(255,255,255,0.15);
            color: #fff;
        }

        .sidebar ul li a.active {
            background: #ffffff;
            color: #0d6efd;
            font-weight: 600;
            border-radius: 0 25px 25px 0;
        }

        /* CONTENT */
        .content {
            margin-left: 240px;
            margin-top: 56px;
            padding: 25px;
        }
    </style>
</head>
<body>

<!-- NAVBAR -->
<nav class="navbar navbar-dark bg-primary fixed-top">
    <div class="container-fluid">
        <span class="navbar-brand">📊 Aplikasi e-BOS</span>
        <div class="text-white">
            👤 <?= htmlspecialchars($nama_lengkap) ?> 
            <a href="logout.php" class="btn btn-sm btn-light ms-2">Logout</a>
        </div>
    </div>
</nav>

<!-- SIDEBAR -->
<div class="sidebar">
    <div class="title">APP-e-BOS 2025 V.1</div>

    <ul>

        <!-- MENU UMUM (ADMIN & USER) -->
        <li>
            <a href="dashboard.php" class="<?= basename($_SERVER['PHP_SELF'])=='dashboard.php'?'active':'' ?>">
                🏠 Dashboard
            </a>
        </li>

        <?php if ($role === 'admin') { ?>
            <!-- MENU KHUSUS ADMIN -->
            <li><a href="users.php">👤 Users</a></li>
            <li><a href="profil_sekolah.php">🏫 Profil Sekolah</a></li>
            <li><a href="list_penganggaran.php">📊 Penganggaran</a></li>
			<li><a href="list_kwitansi.php">🖨️ Cetak Kwitansi</a></li>
            <li><a href="bku.php">📒 Rekap BKU</a></li>
            <li><a href="kib.php">🏷️ Rekap KIB</a></li>
            <li><a href="bhp.php">🏦 Rekap BHP</a></li>
            <li><a href="rekening_koran.php">🏦 Upload Rekening Koran</a></li>
            <li><a href="upload_laporan.php">📤 Upload Laporan</a></li>

        <?php } else { ?>
            <!-- MENU KHUSUS USER -->
			<li><a href="profil_sekolah.php">🏫 Profil Sekolah</a></li>
            <li><a href="list_penganggaran.php">📊 Penganggaran</a></li>
			<li><a href="list_kwitansi.php">🖨️ Cetak Kwitansi</a></li>
            <li><a href="bku.php">📒 Rekap BKU</a></li>
            <li><a href="kib.php">🏷️ Rekap KIB</a></li>
            <li><a href="bhp.php">🏦 Rekap BHP</a></li>
			<li><a href="rekening_koran.php">🏦 Upload Rekening Koran</a></li>
            <li><a href="upload_laporan.php">📤 Upload Laporan</a></li>
        <?php } ?>

        <!-- LOGOUT -->
        <li class="mt-3">
            <a href="logout.php" style="color:#ffdede;">
                🚪 Logout
            </a>
        </li>

    </ul>
</div>


<?php
// ==========================
// DATA CONTOH (AMAN)
// ==========================
$data = [
    [
        'judul'  => 'RKAS BOSP Reguler 2026',
        'ket'    => 'Draft perencanaan',
        'status' => 'Draft'
    ],
    [
        'judul'  => 'RKAS BOSP Reguler 2025',
        'ket'    => 'Sudah disahkan',
        'status' => 'Sudah Disahkan'
    ]
];
?>
<!-- CONTENT -->
<div class="content">
    <h4>Selamat Datang di e-BOS</h4>
    <p class="text-muted">Sistem Pengelolaan Dana BOS Sekolah</p>


<?php foreach($data as $d): ?>
<div class="card mb-3 shadow-sm">
    <div class="card-body d-flex justify-content-between align-items-center">
        <div>
            <b><?= htmlspecialchars($d['judul']) ?></b><br>
            <small class="text-muted"><?= htmlspecialchars($d['ket']) ?></small>
        </div>

        <div>
            <?php if($d['status']=="Draft"){ ?>
                <span class="badge bg-primary">Draft</span>
            <?php } else { ?>
                <span class="badge bg-success">Sudah Disahkan</span>
            <?php } ?>
        </div>

        <div>
            <a href="list_penganggaran.php" class="btn btn-sm btn-outline-primary">input</a>
            <a href="#" class="btn btn-sm btn-outline-warning">Cetak</a>
            <?php if($d['status']=="Draft"){ ?>
            <a href="#" class="btn btn-sm btn-outline-danger">Hapus</a>
            <?php } ?>
        </div>
    </div>
</div>
<?php endforeach; ?>

    <div class="alert alert-success mt-4">
        ✅ Login berhasil. Silakan pilih menu di sebelah kiri.
    </div>
</div>

</body>
</html>
