<?php
$pageTitle2 = $pageTitle ?? 'Dashboard';
$topbarAvatar = BASE_URL . 'assets/images/default-avatar.png';
if (isLoggedIn()) {
    global $pdo;
    try {
        $tbStmt = $pdo->prepare("SELECT p.gambar FROM users u LEFT JOIN pegawai p ON u.pegawai_id = p.id WHERE u.id = ?");
        $tbStmt->execute([currentUserId()]);
        $tbRes = $tbStmt->fetch();
        if ($tbRes && !empty($tbRes['gambar'])) {
            $topbarAvatar = getPegawaiImage($tbRes['gambar']);
        }
    } catch (Exception $e) {}
}
?>
<div style="background:rgba(13,13,13,0.8);border-bottom:1px solid rgba(255,255,255,0.05);padding:.75rem 1.5rem;display:flex;align-items:center;justify-content:space-between;backdrop-filter:blur(10px);position:sticky;top:0;z-index:100">
  <div style="display:flex;align-items:center;gap:1rem">
    <button class="sidebar-toggle" onclick="toggleSidebar()"><i class="fas fa-bars"></i></button>
    <div>
      <div style="font-size:1.1rem;font-weight:700;color:#fff"><?= htmlspecialchars($pageTitle2) ?></div>
      <?php if(isset($breadcrumb)): ?>
      <nav><ol class="breadcrumb mb-0" style="font-size:.75rem">
        <?php foreach($breadcrumb as $i=>$b): ?>
          <?php if($i<count($breadcrumb)-1): ?>
            <li class="breadcrumb-item"><a href="<?= $b['url'] ?>"><?= $b['label'] ?></a></li>
          <?php else: ?>
            <li class="breadcrumb-item active"><?= $b['label'] ?></li>
          <?php endif; ?>
        <?php endforeach; ?>
      </ol></nav>
      <?php endif; ?>
    </div>
  </div>
  <div style="display:flex;align-items:center;gap:1rem">
    <input type="search" class="search-box d-none d-md-block" placeholder="Cari pegawai..." id="globalSearch">
    <div style="position:relative">
      <button class="btn btn-sm" style="background:rgba(255,255,255,0.05);border:1px solid rgba(255,255,255,0.1);color:#ccc;border-radius:10px;padding:.4rem .8rem"><i class="fas fa-bell"></i></button>
    </div>
    <a href="<?= BASE_URL ?>modules/auth/profile.php" style="width:36px;height:36px;border-radius:50%;background:rgba(204,0,1,0.2);border:2px solid rgba(204,0,1,0.4);display:flex;align-items:center;justify-content:center;cursor:pointer;overflow:hidden;text-decoration:none">
      <img src="<?= htmlspecialchars($topbarAvatar) ?>" alt="Profile" style="width:100%;height:100%;object-fit:cover;">
    </a>
  </div>
</div>
