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

$title = '质押挖矿管理';
ob_start();
$records = $db->query("SELECT r.*, u.username, u.uid FROM staking_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>
                <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><?= htmlspecialchars($r['plan_name']) ?></td>
                <td><strong><?= number_format($r['amount'], 2) ?> <?= $r['symbol'] ?></strong></td>
                <td><?= $r['daily_profit'] ?>%</td>
                <td><?= $r['period'] ?>天<br><small><?= $r['end_date'] ?></small></td>
                <td><span class="badge <?= $r['status'] === 'running' ? 'bg-primary' : 'bg-secondary' ?>"><?= $r['status'] === 'running' ? '运行中' : '已结束' ?></span></td>
            </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
</div>
<?php
$content = ob_get_clean();
renderAdminPage($content, $title);
?>
