<?php
/**
 * layouts/navbar.php
 *
 * Top navigation bar — matches original modX sb-topnav output.
 * Requires lib/auth.php to already be included (for getCurrentUser()).
 */
$currentUser = getCurrentUser() ?? ['fullname' => '', 'email' => ''];
$siteName    = $siteName ?? 'Crop Monitor';
?>
<nav class="sb-topnav navbar navbar-expand-lg navbar-dark bg-success">

    <!-- Brand -->
    <a class="navbar-brand ps-3 text-white" href="/dashboard/dashboard.php">
        <?= htmlspecialchars($siteName, ENT_QUOTES, 'UTF-8') ?>
    </a>

    <!-- Sidebar toggle -->
    <button type="button" class="btn btn-link btn-sm order-1 order-lg-0 me-4 me-lg-0" id="sidebarToggle" href="#">
        <i class="fas fa-bars"></i>
    </button>

    <!-- Right-side user dropdown -->
    <div class="d-none d-md-inline-block form-inline ms-auto me-0 me-md-3 my-2 my-md-0"></div>

    <ul class="navbar-nav ms-auto ms-md-0 me-3 me-lg-4">
        <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle" id="userDropdown" href="#"
               role="button" data-bs-toggle="dropdown" aria-expanded="false">
                <i class="fas fa-user-circle fa-fw"></i>
                <span class="d-none d-lg-inline text-white small ms-1">
                    <?= htmlspecialchars($currentUser['fullname'], ENT_QUOTES, 'UTF-8') ?>
                </span>
            </a>
            <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="userDropdown">
                <li>
                    <a class="dropdown-item fw-bold" href="/dashboard/client-settings/update-details.php">
                        <?= htmlspecialchars($currentUser['fullname'], ENT_QUOTES, 'UTF-8') ?>
                    </a>
                </li>
                <li>
                    <a class="dropdown-item" href="/dashboard/client-settings/update-details.php#contact-details">
                        Edit Profile
                    </a>
                </li>
                <li>
                    <a class="dropdown-item" href="/login/change-password.php">
                        Change Password
                    </a>
                </li>
                <li>
                    <a class="dropdown-item" href="/dashboard/inbox.php">
                        Inbox
                    </a>
                </li>
                <li><hr class="dropdown-divider"></li>
                <li>
                    <a class="dropdown-item" href="/login/logout.php">
                        <i class="fas fa-sign-out-alt fa-sm fa-fw me-2 text-gray-400"></i>
                        Logout
                    </a>
                </li>
            </ul>
        </li>
    </ul>

</nav>
