<?php use App\Helpers\Helper; ?>
<div class="d-flex justify-content-between align-items-center mb-4">
  <h1 class="admin-page-title">Bookings</h1>
</div>

<!-- Status tabs -->
<div class="d-flex gap-2 mb-4 flex-wrap">
  <a href="<?= APP_URL ?>/admin/bookings" class="btn btn-sm <?= !$status?'btn-primary':'btn-outline-secondary' ?>">All (<?= array_sum($statusCounts) ?>)</a>
  <?php foreach (['pending'=>'warning','approved'=>'success','rejected'=>'danger','cancelled'=>'secondary','checked_in'=>'info','checked_out'=>'dark'] as $s=>$c): ?>
  <a href="<?= APP_URL ?>/admin/bookings?status=<?= $s ?>" class="btn btn-sm btn-outline-<?= $c ?> <?= $status===$s?'active':'' ?>">
    <?= ucfirst(str_replace('_',' ',$s)) ?> <?php if(isset($statusCounts[$s])): ?>(<?= $statusCounts[$s] ?>)<?php endif; ?>
  </a>
  <?php endforeach; ?>
</div>

<div class="data-card">
  <div class="table-responsive">
    <table class="table mb-0">
      <thead><tr><th>Ref</th><th>Visitor</th><th>Property / Unit</th><th>Move-in</th><th>Fee</th><th>Payment</th><th>Status</th><th>Date</th><th>Action</th></tr></thead>
      <tbody>
        <?php foreach ($bookings as $b): ?>
        <tr>
          <td class="fw-600 text-primary small"><?= Helper::e($b['booking_ref']) ?></td>
          <td>
            <div class="fw-600 small"><?= Helper::e($b['visitor_name']) ?></div>
            <div class="text-muted" style="font-size:0.72rem"><?= Helper::e($b['visitor_phone']) ?></div>
          </td>
          <td class="small"><?= Helper::e($b['property_name']) ?> / <?= Helper::e($b['unit_number']) ?></td>
          <td class="small"><?= Helper::date($b['desired_move_in'] ?? '') ?></td>
          <td><?= Helper::money($b['booking_fee']) ?></td>
          <td><?= Helper::statusBadge($b['payment_status']) ?></td>
          <td><?= Helper::statusBadge($b['status']) ?></td>
          <td class="small text-muted"><?= Helper::timeAgo($b['created_at']) ?></td>
          <td><a href="<?= APP_URL ?>/admin/bookings/<?= $b['id'] ?>" class="btn btn-sm btn-outline-primary">View</a></td>
        </tr>
        <?php endforeach; ?>
        <?php if (empty($bookings)): ?>
        <tr><td colspan="9" class="text-center py-5 text-muted">No bookings found.</td></tr>
        <?php endif; ?>
      </tbody>
    </table>
  </div>
</div>
