<?php
require_once __DIR__ . '/layout.php';
$db = db();

$title = '兑换管理';
ob_start();
$records = $db->query("SELECT r.*, u.username, u.uid FROM exchange_records r JOIN users u ON r.user_id = u.id ORDER BY r.created_at DESC")->fetchAll();
?>
<div class="d-flex justify-content-between align-items-center mb-4">
    <div class="d-flex align-items-center gap-3">
        <a href="index.php" class="btn btn-outline-secondary btn-sm"><i class="bi bi-arrow-left"></i> 返回</a>
        <h4 class="mb-0">兑换记录明细</h4>
    </div>
</div>
<div class="table-container">
    <table class="table table-hover">
        <thead>
            <tr class="small text-muted">
                <th>ID</th>
                <th>用户</th>
                <th>消耗</th>
                <th>获得</th>
                <th>汇率</th>
                <th>时间</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($records as $r): ?>
            <tr>
                <td><?= $r['id'] ?></td>
                <td><?= htmlspecialchars($r['username']) ?><br><code class="small"><?= $r['uid'] ?></code></td>
                <td><span class="text-danger"><?= number_format($r['from_amount'], 4) ?> <?= $r['from_symbol'] ?></span></td>
                <td><span class="text-success"><?= number_format($r['to_amount'], 4) ?> <?= $r['to_symbol'] ?></span></td>
                <td><?= number_format($r['rate'], 6) ?></td>
                <td><small><?= $r['created_at'] ?></small></td>
            </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
</div>
<?php
$content = ob_get_clean();
renderAdminPage($content, $title);
?>
