<?php
requireLogin();
$pengaturan = getPengaturan($pdo);
$tahunAktif = getTahunAjaranAktif($pdo);
$user = currentUser();
?>
<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <title><?= isset($pageTitle) ? htmlspecialchars($pageTitle) . ' - ' : '' ?>Keuangan Sekolah</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css">
    <link rel="stylesheet" href="https://cdn.datatables.net/1.13.8/css/dataTables.bootstrap5.min.css">
    <link rel="stylesheet" href="<?= isset($inSubfolder) ? '../' : '' ?>assets/css/style.css?v=<?= @filemtime(__DIR__ . '/../assets/css/style.css') ?: time() ?>">
    <?php if (isset($extraCss)) echo $extraCss; ?>
</head>
<body>
<div class="app-wrapper">
    <!-- TOPBAR -->
    <nav class="topbar d-flex align-items-center justify-content-between px-3">
        <div class="d-flex align-items-center gap-2">
            <button class="btn btn-sm btn-light d-lg-none" id="sidebarToggle"><i class="bi bi-list fs-5"></i></button>
            <span class="fw-semibold d-none d-md-inline"><?= htmlspecialchars($pengaturan['nama_sekolah'] ?? '') ?></span>
        </div>
        <div class="d-flex align-items-center gap-3">
            <?php if ($tahunAktif): ?>
                <span class="badge bg-light text-dark border d-none d-sm-inline">
                    <i class="bi bi-calendar3"></i> T.A. <?= htmlspecialchars($tahunAktif['nama']) ?> (<?= htmlspecialchars($tahunAktif['semester']) ?>)
                </span>
            <?php endif; ?>
            <div class="dropdown">
                <a href="#" class="d-flex align-items-center gap-2 text-decoration-none text-dark dropdown-toggle" data-bs-toggle="dropdown">
                    <i class="bi bi-person-circle fs-5"></i>
                    <span class="d-none d-sm-inline"><?= htmlspecialchars($user['nama']) ?></span>
                </a>
                <ul class="dropdown-menu dropdown-menu-end">
                    <li><span class="dropdown-item-text small text-muted"><?= htmlspecialchars(ucfirst($user['role'])) ?></span></li>
                    <li><hr class="dropdown-divider"></li>
                    <li><a class="dropdown-item" href="<?= isset($inSubfolder) ? '../' : '' ?>logout.php"><i class="bi bi-box-arrow-right"></i> Keluar</a></li>
                </ul>
            </div>
        </div>
    </nav>