<?php
if (!isset($_SESSION)) {
    session_start();
}
?>
<!DOCTYPE html>
<html lang="sr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Royal Transport</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css">
    <link rel="stylesheet" href="dark-theme.css">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <style>
        .compact-view .table {
            font-size: 0.85rem;
        }
        .compact-view .table th,
        .compact-view .table td {
            padding: 0.3rem 0.5rem;
        }
        .compact-view .btn-sm {
            padding: 0.2rem 0.4rem;
            font-size: 0.75rem;
        }
        .compact-view .badge {
            font-size: 0.7rem;
            padding: 0.25em 0.4em;
        }
        .navbar {
            background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%) !important;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
            padding: 0.75rem 0;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        }
        .navbar-brand {
            padding: 0.5rem 1rem;
            transition: transform 0.2s ease;
        }
        .navbar-brand:hover {
            transform: scale(1.05);
        }
        .navbar-brand img {
            filter: drop-shadow(0 2px 4px rgba(255, 255, 255, 0.1));
        }
        .nav-link {
            padding: 0.5rem 1rem !important;
            margin: 0 0.25rem;
            border-radius: 6px;
            transition: all 0.3s ease;
            position: relative;
            font-weight: 500;
            display: flex !important;
            align-items: center;
            justify-content: center;
            font-size: 14px;
        }
        .nav-link:hover {
            background-color: rgba(255, 255, 255, 0.1);
            transform: translateY(-1px);
        }
        .nav-link.active {
            background-color: rgba(255, 255, 255, 0.15);
        }
        .nav-link i {
            margin-right: 0.5rem;
            font-size: 1rem;
            display: flex;
            align-items: center;
        }
        #themeToggle {
            padding: 0.5rem 0.75rem;
            border-radius: 50%;
            transition: all 0.3s ease;
            border: none;
            background: transparent;
        }
        #themeToggle:hover {
            background-color: rgba(255, 255, 255, 0.1);
            transform: rotate(15deg) scale(1.1);
        }
        #themeToggle i {
            font-size: 1.2rem;
        }
        .dropdown-menu {
            border: 1px solid rgba(255, 255, 255, 0.1);
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
            margin-top: 0.5rem;
        }
        .dropdown-item {
            transition: all 0.2s ease;
            padding: 0.5rem 1rem;
            display: flex;
            align-items: center;
        }
        .dropdown-item:hover {
            background-color: rgba(255, 255, 255, 0.1);
            padding-left: 1.25rem;
        }
        .dropdown-item i {
            margin-right: 0.5rem;
            width: 16px;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .badge {
            font-size: 0.7rem;
            padding: 0.25rem 0.5rem;
            animation: pulse 2s infinite;
        }
        @keyframes pulse {
            0%, 100% { opacity: 1; }
            50% { opacity: 0.7; }
        }
        .navbar-toggler {
            border: 1px solid rgba(255, 255, 255, 0.2);
            padding: 0.25rem 0.5rem;
        }
        .navbar-toggler:focus {
            box-shadow: 0 0 0 0.2rem rgba(255, 255, 255, 0.1);
        }
        @media (max-width: 991px) {
            .navbar-nav {
                margin-top: 1rem;
            }
            .nav-link {
                margin: 0.25rem 0;
            }
        }
    </style>
</head>
<body data-bs-theme="dark">
    <nav class="navbar navbar-expand-lg navbar-dark mb-4">
        <div class="container-fluid">
            <a class="navbar-brand d-flex align-items-center" href="index.php">
                <img src="icon.png" alt="Royal Transport" class="img-fluid me-2" style="height: 35px;">
                <span class="fw-bold d-none d-md-inline">Royal Limo</span>
            </a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav me-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="index.php">
                            <i class="bi bi-list-ul"></i>Lista vožnji
                        </a>
                    </li>
                    <?php if (isset($_SESSION['user']) && ($_SESSION['user']['role'] === 'admin' || $_SESSION['user']['role'] === 'user')): ?>
                        <li class="nav-item">
                            <a class="nav-link" href="statistika_komitenti.php">
                                <i class="bi bi-bar-chart"></i>Statistika
                            </a>
                        </li>
                    <?php endif; ?>
                    <?php if (isset($_SESSION['user']) && $_SESSION['user']['role'] === 'admin'): ?>
                        <li class="nav-item">
                            <a class="nav-link" href="users.php">
                                <i class="bi bi-people"></i>Korisnici
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="komitenti.php">
                                <i class="bi bi-building"></i>Komitenti
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="rent_a_car.php">
                                <i class="bi bi-calendar-date"></i>Rent a Car
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="izvestaji.php">
                                <i class="bi bi-file-text"></i>Izveštaji
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link position-relative" href="pending_rides.php">
                                <i class="bi bi-clock-history"></i>Vožnje na čekanju
                                <?php
                                require_once "config.php";
                                $stmt = $conn->prepare("SELECT COUNT(*) as count FROM voznje WHERE status = 'Na čekanju'");
                                $stmt->execute();
                                $countResult = $stmt->get_result();
                                $count = $countResult->fetch_assoc()['count'];
                                if ($count > 0): ?>
                                    <span class="badge bg-danger position-absolute top-0 start-100 translate-middle"><?php echo $count; ?></span>
                                <?php endif; ?>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="podesavanja.php">
                                <i class="bi bi-gear"></i>Podešavanja
                            </a>
                        </li>
                    <?php endif; ?>
                    <li class="nav-item">
                        <a class="nav-link" href="pomoc.php">
                            <i class="bi bi-question-circle"></i>Pomoć
                        </a>
                    </li>
                </ul>
                <?php if (isset($_SESSION['user'])): ?>
                    <ul class="navbar-nav">
                        <li class="nav-item">
                            <button class="btn btn-link nav-link" id="themeToggle">
                                <i class="bi bi-moon-fill"></i>
                            </button>
                        </li>
                        <li class="nav-item dropdown">
                            <a class="nav-link dropdown-toggle d-flex align-items-center" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" title="<?php echo htmlspecialchars($_SESSION['user']['name']); ?>">
                                <i class="bi bi-person-circle me-2"></i>
                            </a>
                            <ul class="dropdown-menu dropdown-menu-end">
                                <li><a class="dropdown-item" href="profile.php"><i class="bi bi-person"></i>Profil</a></li>
                                <li><hr class="dropdown-divider"></li>
                                <li><a class="dropdown-item text-danger" href="logout.php"><i class="bi bi-box-arrow-right"></i>Odjava</a></li>
                            </ul>
                        </li>
                    </ul>
                <?php endif; ?>
            </div>
        </div>
    </nav>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const themeToggle = document.getElementById('themeToggle');
            const themeIcon = themeToggle.querySelector('i');
            
            const savedTheme = localStorage.getItem('theme') || 'dark';
            document.body.setAttribute('data-bs-theme', savedTheme);
            updateThemeIcon(savedTheme);
            
            themeToggle.addEventListener('click', function() {
                const currentTheme = document.body.getAttribute('data-bs-theme');
                const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
                
                document.body.setAttribute('data-bs-theme', newTheme);
                localStorage.setItem('theme', newTheme);
                updateThemeIcon(newTheme);
            });
            
            function updateThemeIcon(theme) {
                if (theme === 'dark') {
                    themeIcon.classList.remove('bi-sun-fill');
                    themeIcon.classList.add('bi-moon-fill');
                } else {
                    themeIcon.classList.remove('bi-moon-fill');
                    themeIcon.classList.add('bi-sun-fill');
                }
            }
            
            const currentPath = window.location.pathname.split('/').pop() || 'index.php';
            const navLinks = document.querySelectorAll('.navbar-nav .nav-link');
            
            navLinks.forEach(link => {
                const linkPath = link.getAttribute('href');
                if (linkPath && (linkPath === currentPath || (currentPath === '' && linkPath === 'index.php'))) {
                    link.classList.add('active');
                }
            });
        });
    </script>
</body>
</html>