<!-- Navbar -->
<nav class="main-header navbar navbar-expand navbar-white navbar-light">
    <ul class="navbar-nav">
        <li class="nav-item">
            <a class="nav-link" href="index.php">
                <i class="fas fa-home"></i> Ana Sayfa
            </a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="flasher.php">
                <i class="fas fa-download"></i> Flasher
            </a>
        </li>
    </ul>
    
    <ul class="navbar-nav ml-auto">
        <?php 
        // Check if user is logged in by checking session
        $is_logged_in = isset($_SESSION['user_id']);
        $user_data = null;
        
        if ($is_logged_in) {
            // Get user data if not already loaded
            if (!isset($user)) {
                $user_id = is_array($_SESSION['user_id']) ? $_SESSION['user_id'][0] : $_SESSION['user_id'];
                $user_sql = "SELECT username, email, role FROM users WHERE id = $user_id";
                $user_result = $GLOBALS['con']->query($user_sql);
                $user_data = $user_result ? $user_result->fetch_assoc() : null;
            } else {
                $user_data = $user;
            }
        }
        ?>
        
        <?php if ($is_logged_in && $user_data): ?>
        <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown">
                <i class="fas fa-user"></i> <?php echo htmlspecialchars($user_data['username']); ?>
            </a>
            <div class="dropdown-menu dropdown-menu-right">
                <a class="dropdown-item" href="profile.php">
                    <i class="fas fa-user-cog"></i> Profil
                </a>
                <div class="dropdown-divider"></div>
                <a class="dropdown-item" href="logout.php">
                    <i class="fas fa-sign-out-alt"></i> Çıkış
                </a>
            </div>
        </li>
        <?php else: ?>
        <li class="nav-item">
            <a class="nav-link" href="login.php">
                <i class="fas fa-sign-in-alt"></i> Giriş Yap
            </a>
        </li>
        <?php endif; ?>
    </ul>
</nav>
