<?php
session_start();
$conn = new mysqli("localhost","root","","breakout_db");
$lb = $conn->query("SELECT username, highscore FROM users ORDER BY highscore DESC LIMIT 10");

$isLoggedIn = isset($_SESSION['user']); // SUDAH DIPERBAIKI
$username = $isLoggedIn ? htmlspecialchars($_SESSION['user']) : null; // SUDAH DIPERBAIKI
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Leaderboard</title>

<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">

<link rel="stylesheet" href="style.css">

</head>
<body class="leaderboard-body">

<h2><i class="fas fa-trophy"></i> Leaderboard</h2>

<<div class="menu">
    <a href="index.php"><i class="fas fa-home"></i> Home</a>

    <?php if($isLoggedIn): ?>
        <a href="logout.php"><i class="fas fa-right-from-bracket"></i> Logout</a>
    <?php else: ?>
        <a href="login.php"><i class="fas fa-sign-in-alt"></i> Login</a>
    <?php endif; ?>
</div>

<div class="board-container">
    <table>
        <thead>
            <tr>
                <th>Username</th>
                <th>Highscore</th>
            </tr>
        </thead>
        <tbody>
            <?php while($r = $lb->fetch_assoc()) { ?>
                <tr>
                    <td><?= htmlspecialchars($r['username']) ?></td>
                    <td><?= htmlspecialchars($r['highscore']) ?></td>
                </tr>
            <?php } ?>
        </tbody>
    </table>
</div>

<a href="index.php" class="back-button">⬅ Back</a>

</body>
</html>