<?php
/**
 * SalonPro X - Header / Top Navigation Partial
 */
$user = \core\Auth::user();
$unreadNotifications = \core\Database::getInstance()->table('notifications')
    ->where('user_id', \core\Auth::id())
    ->where('is_read', 0)
    ->count();
?>
<header class="top-navbar glass-nav">
    <div class="container-fluid">
        <div class="navbar-row">
        <!-- Sidebar Toggle -->
        <div class="nav-left">
            <button class="btn btn-navbar sidebar-toggle" type="button">
                <i class="fas fa-bars"></i>
            </button>
            <div class="page-title">
                <h5 class="mb-0"><?= e($title ?? 'Dashboard') ?></h5>
            </div>
        </div>

        <!-- Navbar Right -->
        <div class="nav-right">
            <!-- Search -->
            <div class="search-box">
                <i class="fas fa-search search-icon"></i>
                <input type="text" class="form-control search-input" placeholder="Search customers, appointments..." id="globalSearch">
            </div>

            <!-- Notifications -->
            <div class="dropdown">
                <button class="btn btn-navbar position-relative" data-bs-toggle="dropdown">
                    <i class="fas fa-bell"></i>
                    <?php if ($unreadNotifications > 0): ?>
                        <span class="notification-badge"><?= $unreadNotifications > 99 ? '99+' : $unreadNotifications ?></span>
                    <?php endif; ?>
                </button>
                <div class="dropdown-menu dropdown-menu-end notification-dropdown glass-dropdown">
                    <div class="dropdown-header">
                        <h6 class="mb-0">Notifications</h6>
                        <a href="<?= url('notifications') ?>" class="btn btn-sm btn-link">View All</a>
                    </div>
                    <div class="notification-list" id="notificationList">
                        <div class="text-center py-3 text-muted">Loading...</div>
                    </div>
                </div>
            </div>

            <!-- User Menu -->
            <div class="dropdown">
                <button class="btn btn-navbar user-dropdown" data-bs-toggle="dropdown">
                    <div class="user-avatar-sm">
                        <?php if ($user && $user->avatar): ?>
                            <img src="<?= uploadUrl($user->avatar) ?>" alt="">
                        <?php else: ?>
                            <div class="avatar-initials"><?= strtoupper(substr($user->first_name ?? 'U', 0, 1) . substr($user->last_name ?? 'S', 0, 1)) ?></div>
                        <?php endif; ?>
                    </div>
                    <div class="user-info d-none d-md-block">
                        <span class="user-name"><?= e($user->first_name ?? 'User') ?> <?= e($user->last_name ?? '') ?></span>
                        <span class="user-role"><?= e(ucfirst($user->role_name ?? '')) ?></span>
                    </div>
                    <i class="fas fa-chevron-down"></i>
                </button>
                <ul class="dropdown-menu dropdown-menu-end glass-dropdown">
                    <li>
                        <a class="dropdown-item" href="<?= url('profile') ?>">
                            <i class="fas fa-user-cog"></i> My Profile
                        </a>
                    </li>
                    <li>
                        <a class="dropdown-item" href="<?= url('settings') ?>">
                            <i class="fas fa-cog"></i> Settings
                        </a>
                    </li>
                    <li><hr class="dropdown-divider"></li>
                    <li>
                        <a class="dropdown-item text-danger" href="<?= url('logout') ?>">
                            <i class="fas fa-sign-out-alt"></i> Logout
                        </a>
                    </li>
                </ul>
            </div>
        </div>
    </div>
    </div>
</header>
