<?php // claims log tab — included by claims.php ?>
<?php if ($tab === 'claims'): ?>
<!-- ── CLAIM LOG TAB ── -->

<div class="sec-hd">
  <div class="sec-hd-title"><i class="bi bi-bookmark-fill"></i>Claim Log
    <span class="chip chip-blue" style="font-size:11px"><?= number_format($cTotal) ?> records</span>
  </div>
  <a href="?tab=claims&export=csv" class="btn-export"><i class="bi bi-download"></i>Export CSV</a>
</div>

<form method="GET" class="log-search">
  <input type="hidden" name="tab" value="claims">
  <input type="text" name="cs" class="frm-ctrl" placeholder="Search customer, phone or voucher…" value="<?= htmlspecialchars($cSearch) ?>">
  <button class="btn-accent" style="padding:9px 16px"><i class="bi bi-search"></i></button>
  <?php if($cSearch): ?><a href="?tab=claims" class="btn-ghost" style="padding:9px 14px"><i class="bi bi-x"></i></a><?php endif; ?>
</form>

<div class="adm-card" style="padding:0;overflow:hidden">
  <?php if(empty($claimRows)): ?>
  <div class="log-empty">
    <i class="bi bi-bookmark"></i>
    <p><?= $cSearch ? 'No claims match your search.' : 'No claims yet.' ?></p>
  </div>
  <?php else: ?>
  <div class="table-responsive">
  <table class="adm-table">
    <thead>
      <tr>
        <th>#</th>
        <th>Customer</th>
        <th>Voucher</th>
        <th>Code</th>
        <th>Status</th>
        <th>Claimed At</th>
        <th>Redeemed At</th>
      </tr>
    </thead>
    <tbody>
    <?php foreach($claimRows as $r): ?>
    <tr>
      <td style="font-family:var(--mono);font-size:11px;color:var(--muted)"><?= $r['id'] ?></td>
      <td>
        <div style="font-weight:600"><?= htmlspecialchars($r['name']) ?></div>
        <div style="font-size:11px;color:var(--muted);font-family:var(--mono)"><?= htmlspecialchars($r['phone']) ?></div>
      </td>
      <td>
        <div style="font-size:13px;font-weight:500"><?= htmlspecialchars($r['event_name']) ?></div>
        <?php if($r['type']): ?><div style="font-size:11px;color:var(--muted)"><?= htmlspecialchars($r['type']) ?></div><?php endif; ?>
      </td>
      <td><span style="font-family:var(--mono);font-size:11px;background:var(--bg);color:var(--accent);padding:3px 8px;border-radius:5px;border:1px solid var(--border)"><?= htmlspecialchars($r['code']) ?></span></td>
      <td>
        <?php if($r['status']==='redeemed'): ?>
          <span class="badge-redeemed"><i class="bi bi-check-circle-fill"></i> Redeemed</span>
        <?php else: ?>
          <span class="badge-pending"><i class="bi bi-hourglass"></i> Pending</span>
        <?php endif; ?>
      </td>
      <td style="font-size:12px;color:var(--muted);white-space:nowrap"><?= fmtDate($r['claimed_at']) ?></td>
      <td style="font-size:12px;white-space:nowrap">
        <?= $r['redeemed_at'] ? '<span style="color:#2dbd87">'.fmtDate($r['redeemed_at']).'</span>' : '<span style="color:var(--muted)">—</span>' ?>
      </td>
    </tr>
    <?php endforeach; ?>
    </tbody>
  </table>
  </div>
  <div class="pg-bar">
    <span><?= number_format($cTotal) ?> claims · Page <?= $cPage ?> of <?= $cPages ?></span>
    <div class="pg-nums"><?= pgLinks($cPage, $cPages, '?tab=claims'.($cSearch?'&cs='.urlencode($cSearch):'').'&cp=') ?></div>
  </div>
  <?php endif; ?>
</div>

