<?php
/**
 * Topbar partial.
 * Requires: $user (from Auth::requireLogin())
 * Optional: $showSearch (default true)
 */
$showSearch = $showSearch ?? true;
$initials = strtoupper(mb_substr($user['name'] ?? '?', 0, 1));
?>
<div class="top-header">
    <button class="burger-btn" id="burgerBtn"><i class="bi bi-list"></i></button>

    <?php if ($showSearch): ?>
    <div class="search-bar flex-grow-1" style="max-width:400px">
        <i class="bi bi-search"></i>
        <input type="text" id="globalSearch" placeholder="Search campaign..." autocomplete="off">
    </div>
    <?php else: ?>
    <div class="flex-grow-1"></div>
    <?php endif; ?>

    <div class="header-right">
        <a href="/dashboard/profile" class="icon-circle icon-circle-outline" title="Profile">
            <i class="bi bi-person-fill"></i>
        </a>
        <div class="icon-circle icon-circle-outline" title="Notifications" style="position:relative">
            <i class="bi bi-bell-fill"></i>
        </div>
        <a href="/dashboard/profile" style="text-decoration:none;display:flex;align-items:center;gap:10px">
            <?php if (!empty($user['profile_pic'])): ?>
                <img src="<?= e($user['profile_pic']) ?>" alt="Profile" class="header-avatar-placeholder" style="width:40px;height:40px;border-radius:50%;object-fit:cover">
            <?php else: ?>
                <div class="header-avatar-placeholder"><?= e($initials) ?></div>
            <?php endif; ?>
            <div class="header-user-info">
                <div class="user-name"><?= e($user['name']) ?></div>
                <div class="user-email"><?= e($user['email']) ?></div>
            </div>
        </a>
    </div>
</div>
