<?php if (is_array($stats ?? null)): ?>
<div class="row">
  <div class="col-md-12">
    <div class="card">
      <div class="card-header"><h4><?= e(app_zh('数据概览')) ?></h4></div>
      <div class="card-body">
        <?php require __DIR__ . '/../partials/stats_overview.php'; ?>
      </div>
    </div>
  </div>
</div>
<?php endif; ?>

<div class="row">
  <div class="col-md-3">
    <div class="card">
      <div class="card-header"><h4><?= e(app_zh('概览')) ?></h4></div>
      <div class="card-body">
        <p><strong><?= e(app_zh('卡密数量：')) ?></strong> <?= e((string)$keysCount) ?></p>
        <p><strong><?= e(app_zh('余额：')) ?></strong> <?= e((string)($user['balance'] ?? 0)) ?></p>
      </div>
    </div>
  </div>
  <div class="col-md-9">
    <div class="card">
      <div class="card-header"><h4><?= e(app_zh('最近操作')) ?></h4></div>
      <div class="card-body">
        <div class="table-responsive">
          <table class="table table-bordered">
            <thead>
              <tr>
                <th>ID</th>
                <th><?= e(app_zh('用户')) ?></th>
                <th><?= e(app_zh('卡密')) ?></th>
                <th><?= e(app_zh('信息')) ?></th>
                <th><?= e(app_zh('时间')) ?></th>
              </tr>
            </thead>
            <tbody>
              <?php if (empty($history)): ?>
              <tr>
                <td colspan="5"><?= e(app_zh('暂无记录')) ?></td>
              </tr>
              <?php else: ?>
                <?php foreach ($history as $row): ?>
                <tr>
                  <td><?= e((string)$row['id']) ?></td>
                  <td><?= e((string)($row['username'] ?? '')) ?></td>
                  <td><?= e((string)($row['user_key'] ?? '')) ?></td>
                  <td><?= e((string)$row['info']) ?></td>
                  <td><?= e((string)$row['created_at']) ?></td>
                </tr>
                <?php endforeach; ?>
              <?php endif; ?>
            </tbody>
          </table>
        </div>
      </div>
    </div>
  </div>
</div>
