<?= $this->extend('admin/layout/default') ?>
<?= $this->section('content') ?>
<div class="content-header">
  <div class="container-fluid">
    <div class="row mb-2">
      <div class="col-sm-6"><h1 class="m-0 text-dark">Payments</h1></div>
      <div class="col-sm-6">
        <ol class="breadcrumb float-sm-right">
          <li class="breadcrumb-item"><a href="<?= url('dashboard') ?>">Dashboard</a></li>
          <li class="breadcrumb-item active">Payments</li>
        </ol>
      </div>
    </div>
  </div>
  </div>
<section class="content">
  <div class="container-fluid">
    <div class="card">
      <div class="card-body table-responsive p-0">
        <table class="table table-hover">
          <thead>
            <tr>
              <th>ID</th>
              <th>Date</th>
              <th>Shop</th>
              <th>Customer</th>
              <th>Amount</th>
              <th>Discount</th>
              <th>Payable</th>
              <th>Status</th>
              <th>Mode</th>
              <th>Order ID</th>
              <th>Payment ID</th>
              <th>Reward Points</th>
            </tr>
          </thead>
          <tbody>
          <?php if (!empty($rows)): ?>
            <?php foreach ($rows as $r): ?>
              <tr>
                <td><?= (int) $r->id ?></td>
                <td><?= esc($r->created_at) ?></td>
                <td><?= esc($r->shop_name) ?></td>
                <td><?= esc($r->customer_name) ?></td>
                <td>₹<?= number_format((float)$r->amount, 2) ?></td>
                <td>₹<?= number_format((float)$r->discount_amount, 2) ?></td>
                <td>₹<?= number_format((float)$r->payable, 2) ?></td>
                <td><span class="badge badge-success"><?= esc($r->status) ?></span></td>
                <td><?= $r->gateway ? ucfirst(esc($r->gateway)) : 'Offline' ?></td>
                <td><?= esc($r->gateway_order_id) ?></td>
                <td><?= esc($r->gateway_payment_id) ?></td>
                <td><?= (int) ($r->reward_points ?? 0) ?></td>
              </tr>
            <?php endforeach ?>
          <?php else: ?>
            <tr><td colspan="12" class="text-center text-muted">No payments found</td></tr>
          <?php endif ?>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</section>
<?= $this->endSection() ?>
