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

$db = new PDO('sqlite:' . dirname(__DIR__) . '/data/app.db');

// Hent de 50 seneste spins
$rows = $db->query('SELECT * FROM slots_spins ORDER BY id DESC LIMIT 50')->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Emote Slots</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
<div class="wrap">
    <div class="card">
        <h2>🎰 Emote Slot – Seneste spins</h2>
        <p><a class="btn" href="index.php">← Tilbage</a></p>

        <table>
            <tr>
                <th>Tid</th>
                <th>Bruger</th>
                <th>Indsats</th>
                <th>Resultat</th>
                <th>Udbetaling</th>
            </tr>

            <?php foreach ($rows as $r): ?>
                <?php $res = $r['r1'] . ' | ' . $r['r2'] . ' | ' . $r['r3']; ?>
                <tr>
                    <td><?php echo htmlspecialchars($r['ts']); ?></td>
                    <td>@<?php echo htmlspecialchars($r['user_login']); ?></td>
                    <td><?php echo (int)$r['amount']; ?></td>
                    <td><?php echo htmlspecialchars($res); ?></td>
                    <td><?php echo (int)$r['payout']; ?></td>
                </tr>
            <?php endforeach; ?>
        </table>
    </div>
</div>
</body>
</html>
