<?php
require_once __DIR__ . '/includes/bootstrap.php';
require_login();

$top = DB::fetchAll(
    "SELECT id, name, race, exp, stat_win, stat_battle
     FROM users
     WHERE is_banned = 0
     ORDER BY exp DESC
     LIMIT 50"
);

$page_title = __('menu_ranking');
require __DIR__ . '/includes/header.php';
?>

<h1>🏆 <?= e(__('menu_ranking')) ?></h1>

<table class="tbl">
    <thead>
        <tr>
            <th>#</th>
            <th><?= __('character') ?></th>
            <th><?= __('level') ?></th>
            <th><?= __('experience') ?></th>
            <th><?= __('fight_won') ?></th>
        </tr>
    </thead>
    <tbody>
        <?php foreach ($top as $i => $u):
            $lvl = User::calculateLevel((int)$u['exp']);
        ?>
        <tr>
            <td><strong>#<?= $i + 1 ?></strong></td>
            <td>
                <img src="<?= APP_URL ?>/assets/img/race<?= (int)$u['race'] ?>small.gif"
                     alt="" style="vertical-align:middle; margin-right:0.4rem;">
                <?= e($u['name']) ?>
            </td>
            <td><?= $lvl ?></td>
            <td><?= format_number((int)$u['exp']) ?></td>
            <td><?= (int)$u['stat_win'] ?>/<?= (int)$u['stat_battle'] ?></td>
        </tr>
        <?php endforeach; ?>
    </tbody>
</table>

<?php require __DIR__ . '/includes/footer.php'; ?>
