<div class="card p-3">
  <div class="d-flex justify-content-between align-items-center mb-3">
    <h5 class="mb-0">All Loans</h5>
    <div>
      <a href="/admin/loans?status=pending" class="btn btn-sm btn-outline-secondary">Pending</a>
      <a href="/admin/loans?status=approved" class="btn btn-sm btn-outline-secondary">Approved</a>
      <a href="/admin/loans?status=disbursed" class="btn btn-sm btn-outline-secondary">Disbursed</a>
    </div>
  </div>

  <div class="table-responsive">
    <table class="table table-hover">
      <thead>
        <tr>
          <th>UID</th><th>User</th><th>Product</th><th>Amount</th><th>Term</th><th>Status</th><th>Created</th><th>Action</th>
        </tr>
      </thead>
      <tbody>
        <?php foreach($loans as $loan): ?>
        <tr>
          <td><?= esc($loan['loan_uid']) ?></td>
          <td><?= esc($loan['user_name'] ?? $loan['user_id']) ?></td>
          <td><?= esc($loan['product_name'] ?? $loan['product_id']) ?></td>
          <td>₹ <?= esc(number_format($loan['amount'],2)) ?></td>
          <td><?= esc($loan['term']) ?></td>
          <td><span class="badge bg-<?= $loan['status']=='pending'?'warning text-dark':($loan['status']=='disbursed'?'success':'info') ?>"><?= esc($loan['status']) ?></span></td>
          <td><?= esc($loan['created_at']) ?></td>
          <td>
            <a class="btn btn-sm btn-primary" href="/admin/loans/view/<?= $loan['id'] ?>">View</a>
          </td>
        </tr>
        <?php endforeach; ?>
      </tbody>
    </table>
  </div>
</div>