<?php
// Get dashboard URL based on user type
$dashboardUrl = '#';
$dashboardText = 'My Dashboard';

if (Auth::check()) {
    switch (Auth::userType()) {
        case 'admin':
            $dashboardUrl  = APP_URL . '/admin/index.php';
            $dashboardText = 'Admin Dashboard';
            break;
        case 'vendor':
            $dashboardUrl  = APP_URL . '/vendor/index.php';
            $dashboardText = 'Vendor Dashboard';
            break;
        case 'customer':
            $dashboardUrl  = APP_URL . '/customer/index.php';
            $dashboardText = 'My Dashboard';
            break;
    }
}
?>

<!-- start navbar -->
<nav class="navbar navbar-expand-lg navbar-light sticky-top">
    <div class="container">
        <a class="navbar-brand m-0" href="<?= APP_URL ?>/index.php">
            <img class="logo-white" src="<?= APP_URL ?>/assets/images/logo-white.png" alt="Rentidium">
            <img class="logo-dark" src="<?= APP_URL ?>/assets/images/logo.png" alt="Rentidium" style="width: 200px; height:auto">
        </a>
        <div class="d-flex order-lg-2">
            <!-- start Favorites button -->
            <?php /*
            <a href="<?= Auth::check() ? (Auth::isCustomer() ? APP_URL . '/customer/favorites.php' : '#') : APP_URL . '/auth/login.php' ?>" 
               class="d-flex align-items-center justify-content-center p-0 btn-user position-relative" 
               data-bs-toggle="tooltip" data-bs-placement="bottom" 
               data-bs-custom-class="custom-tooltip" data-bs-title="Favourite">
                <i class="fa-solid fa-heart"></i>
                <span class="align-items-center bg-primary d-flex end-0 fs-11 justify-content-center nav-count position-absolute rounded-circle text-white">0</span>
            </a>
            */ ?>
            <!-- end /. Favorites button -->
            
            <!-- start Theme Toggle button -->
            <button type="button" id="themeToggleBtn" 
                    class="align-items-center bg-transparent border-0 btn-user d-flex justify-content-center p-0">
                <i class="fa-solid fa-moon"></i>
            </button>
            <!-- end /. Theme Toggle button -->
            
            <!-- start Sign Up / Logout button -->
            <?php if (Auth::check()): ?>
                <!-- Logged in - Show Logout -->
                <a href="<?= APP_URL ?>/auth/logout.php" 
                   class="d-flex align-items-center justify-content-center p-0 btn-user" 
                   data-bs-toggle="tooltip" data-bs-placement="bottom" 
                   data-bs-custom-class="custom-tooltip" data-bs-title="Logout"
                   onclick="return confirm('Are you sure you want to logout?')">
                    <i class="fa-solid fa-right-from-bracket"></i>
                </a>
            <?php else: ?>
                <!-- Not logged in - Show Sign Up -->
                <a href="<?= APP_URL ?>/auth/register.php" 
                   class="d-flex align-items-center justify-content-center p-0 btn-user" 
                   data-bs-toggle="tooltip" data-bs-placement="bottom" 
                   data-bs-custom-class="custom-tooltip" data-bs-title="Sign Up">
                    <i class="fa-solid fa-user-plus"></i>
                </a>
            <?php endif; ?>
            <!-- end /. Sign Up / Logout button -->
            
            <!-- start Add Listing / Dashboard / Login button -->
            <?php if (Auth::check()): ?>
                <!-- Logged in - Show Dashboard -->
                <a href="<?= $dashboardUrl ?>" 
                   class="btn btn-primary d-none d-sm-flex fw-medium gap-2 hstack rounded-5">
                    <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-speedometer2" viewBox="0 0 16 16">
                        <path d="M8 4a.5.5 0 0 1 .5.5V6a.5.5 0 0 1-1 0V4.5A.5.5 0 0 1 8 4M3.732 5.732a.5.5 0 0 1 .707 0l.915.914a.5.5 0 1 1-.708.708l-.914-.915a.5.5 0 0 1 0-.707M2 10a.5.5 0 0 1 .5-.5h1.586a.5.5 0 0 1 0 1H2.5A.5.5 0 0 1 2 10m9.5 0a.5.5 0 0 1 .5-.5h1.5a.5.5 0 0 1 0 1H12a.5.5 0 0 1-.5-.5m.754-4.246a.39.39 0 0 0-.527-.02L7.547 9.31a.91.91 0 1 0 1.302 1.258l3.434-4.297a.39.39 0 0 0-.029-.518z"/>
                        <path fill-rule="evenodd" d="M0 10a8 8 0 1 1 15.547 2.661c-.442 1.253-1.845 1.602-2.932 1.25C11.309 13.488 9.475 13 8 13c-1.474 0-3.31.488-4.615.911-1.087.352-2.49.003-2.932-1.25A8 8 0 0 1 0 10m8-7a7 7 0 0 0-6.603 9.329c.203.575.923.876 1.68.63C4.397 12.533 6.358 12 8 12s3.604.532 4.923.96c.757.245 1.477-.056 1.68-.631A7 7 0 0 0 8 3"/>
                    </svg>
                    <div class="vr d-none d-sm-inline-block"></div>
                    <span class="d-none d-sm-inline-block"><?= $dashboardText ?></span>
                </a>
            <?php else: ?>
                <!-- Not logged in - Show Login -->
                <a href="<?= APP_URL ?>/auth/login.php" 
                   class="btn btn-primary d-none d-sm-flex fw-medium gap-2 hstack rounded-5">
                    <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-box-arrow-in-right" viewBox="0 0 16 16">
                        <path fill-rule="evenodd" d="M6 3.5a.5.5 0 0 1 .5-.5h8a.5.5 0 0 1 .5.5v9a.5.5 0 0 1-.5.5h-8a.5.5 0 0 1-.5-.5v-2a.5.5 0 0 0-1 0v2A1.5 1.5 0 0 0 6.5 14h8a1.5 1.5 0 0 0 1.5-1.5v-9A1.5 1.5 0 0 0 14.5 2h-8A1.5 1.5 0 0 0 5 3.5v2a.5.5 0 0 0 1 0z"/>
                        <path fill-rule="evenodd" d="M11.854 8.354a.5.5 0 0 0 0-.708l-3-3a.5.5 0 1 0-.708.708L10.293 7.5H1.5a.5.5 0 0 0 0 1h8.793l-2.147 2.146a.5.5 0 0 0 .708.708z"/>
                    </svg>
                    <div class="vr d-none d-sm-inline-block"></div>
                    <span class="d-none d-sm-inline-block">Login</span>
                </a>
            <?php endif; ?>
            <!-- end /. Add Listing / Dashboard / Login button -->
            
            <!-- start navbar toggle button -->
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                <span id="nav-icon" class="">
                    <span></span>
                    <span></span>
                    <span></span>
                </span>
            </button>
            <!-- end /. navbar toggle button -->
        </div>
        <div class="collapse navbar-collapse" id="navbarSupportedContent">
            <ul class="navbar-nav m-auto mb-2 mb-lg-0">
                <li class="nav-item">
                    <a class="nav-link" href="<?= APP_URL ?>/index.php">Home</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="<?= APP_URL ?>/items.php">Items</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="<?= APP_URL ?>/about-us.php">About Us</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="<?= APP_URL ?>/faqs.php">FAQ</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="<?= APP_URL ?>/contact-us.php">Contact</a>
                </li>
                
                <?php if (Auth::check()): ?>
                <!-- Mobile Dashboard Link (visible on small screens) -->
                <li class="nav-item d-sm-none">
                    <a class="nav-link" href="<?= $dashboardUrl ?>">
                        <i class="fa-solid fa-speedometer2 me-2"></i><?= $dashboardText ?>
                    </a>
                </li>
                
                <!-- Mobile Logout Link (visible on small screens) -->
                <li class="nav-item d-sm-none">
                    <a class="nav-link" href="<?= APP_URL ?>/auth/logout.php" onclick="return confirm('Are you sure you want to logout?')">
                        <i class="fa-solid fa-right-from-bracket me-2"></i>Logout
                    </a>
                </li>
                <?php else: ?>
                <!-- Mobile Login Link (visible on small screens) -->
                <li class="nav-item d-sm-none">
                    <a class="nav-link" href="<?= APP_URL ?>/auth/login.php">
                        <i class="fa-solid fa-right-to-bracket me-2"></i>Login
                    </a>
                </li>
                
                <!-- Mobile Sign Up Link (visible on small screens) -->
                <li class="nav-item d-sm-none">
                    <a class="nav-link" href="<?= APP_URL ?>/auth/register.php">
                        <i class="fa-solid fa-user-plus me-2"></i>Sign Up
                    </a>
                </li>
                <?php endif; ?>
            </ul>
        </div>
    </div>
</nav>
<!-- end navbar -->