<?php
/** @var array<int,array> $payments */
?>

<?= $this->extend('layout/management_layout') ?>

<?= $this->section('content') ?>
<div class="container-fluid py-3">
  <div class="d-flex align-items-center justify-content-between mb-3">
    <h1 class="h4 m-0">Payments</h1>
  </div>

  <div class="card">
    <div class="card-body">
      <div class="table-responsive">
        <table class="table table-sm align-middle">
          <thead class="table-light">
            <tr>
              <th>Date</th>
              <th>Invoice #</th>
              <th class="text-end">Paid Amount</th>
              <th class="text-end">Invoice Balance</th>
              <th>Method</th>
              <th>Payment Status</th>
              <th>Invoice Status</th>
              <th>School Year</th>
            </tr>
          </thead>
          <tbody>
          <?php if (empty($payments)): ?>
            <tr>
              <td colspan="8" class="text-center text-muted py-4">No payment</td>
            </tr>
          <?php else: ?>
            <?php foreach ($payments as $p): ?>
              <tr>
                <td><?= esc(!empty($p['payment_date']) ? local_date($p['payment_date'], 'm-d-Y') : '') ?></td>
                <td><?= esc($p['invoice_number'] ?? ('#' . (int)($p['invoice_id'] ?? 0))) ?></td>
                <td class="text-end">$<?= number_format((float)($p['paid_amount'] ?? 0), 2) ?></td>
                <td class="text-end">$<?= number_format((float)($p['invoice_current_balance'] ?? 0), 2) ?></td>
                <td><?= esc($p['payment_method'] ?? '') ?></td>
                <td><?= esc($p['payment_status'] ?? '') ?></td>
                <td><?= esc($p['invoice_status'] ?? '') ?></td>
                <td><?= esc($p['school_year'] ?? '') ?></td>
              </tr>
            <?php endforeach; ?>
          <?php endif; ?>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>
<?= $this->endSection() ?>
