<?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.1rem;
            border-radius: 6px;
            transition: background-color 0.2s ease;
            font-weight: 500;
            display: flex !important;
            align-items: center;
            gap: 0.4rem;
            font-size: 14px;
        }
        .nav-link:hover {
            background-color: rgba(255, 255, 255, 0.1);
        }
        .nav-link.active {
            background-color: rgba(255, 255, 255, 0.15);
        }
        .nav-link i {
            font-size: 1rem;
            line-height: 1;
            flex-shrink: 0;
        }
        #themeToggle {
            display: inline-flex !important;
            align-items: center;
            justify-content: center;
            width: 36px;
            height: 36px;
            padding: 0 !important;
            border-radius: 50%;
            border: none;
            background: transparent;
            transition: background-color 0.2s ease, transform 0.3s ease;
            color: rgba(255, 255, 255, 0.75);
            margin: 0 0.1rem;
        }
        #themeToggle:hover {
            background-color: rgba(255, 255, 255, 0.1);
            color: #fff;
            transform: rotate(20deg);
        }
        #themeToggle i {
            font-size: 1.1rem;
            line-height: 1;
        }
        .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: background-color 0.15s ease;
            padding: 0.5rem 1rem;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }
        .dropdown-item:hover {
            background-color: rgba(var(--bs-emphasis-color-rgb), 0.08);
        }
        .dropdown-item i {
            width: 16px;
            text-align: center;
            flex-shrink: 0;
        }
        .badge {
            font-size: 0.7rem;
            padding: 0.25rem 0.5rem;
        }
        @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: 0.5rem;
            }
            .nav-link {
                margin: 0.15rem 0;
                justify-content: flex-start;
            }
            #themeToggle {
                margin: 0.15rem 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 (isAdmin()): ?>
                        <li class="nav-item">
                            <a class="nav-link" href="statistika_vozaci.php">
                                <i class="bi bi-person-badge"></i>Stat. vozači
                            </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><span class="d-lg-none">Podešavanja</span>
                            </a>
                        </li>
                    <?php endif; ?>
                    <li class="nav-item">
                        <a class="nav-link" href="pomoc.php">
                            <i class="bi bi-question-circle"></i><span class="d-lg-none">Pomoć</span>
                        </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>