<?= $this->extend('admin/layouts/main') ?>
<?= $this->section('content') ?>

<p class="text-muted mb-3">All invoices billed to hotels for their PMS subscription. Generate a new one from a hotel's detail page.</p>

<div class="card">
    <div class="table-responsive">
        <table class="table mb-0 align-middle">
            <thead>
            <tr><th>Invoice #</th><th>Hotel</th><th>Amount</th><th>Status</th><th>Due</th><th></th></tr>
            </thead>
            <tbody>
            <?php if (empty($invoices)): ?>
                <tr><td colspan="6" class="text-center text-muted py-4">No invoices yet.</td></tr>
            <?php endif; ?>
            <?php foreach ($invoices as $inv):
                $badge = (new \Config\Lookups())->invoiceStatuses[$inv->status]['badge'] ?? 'secondary'; ?>
                <tr>
                    <td><a href="<?= site_url('admin/invoices/' . $inv->id) ?>" class="text-decoration-none fw-semibold"><?= esc($inv->invoice_number) ?></a></td>
                    <td><a href="<?= site_url('admin/tenants/' . $inv->tenant_id) ?>" class="text-decoration-none"><?= esc($inv->hotel_name) ?></a></td>
                    <td><?= format_money($inv->amount) ?></td>
                    <td><span class="badge bg-<?= $badge ?>"><?= esc(ucfirst($inv->status)) ?></span></td>
                    <td class="text-muted small"><?= $inv->due_date ? esc(date('d M Y', strtotime($inv->due_date))) : '—' ?></td>
                    <td class="text-end"><a href="<?= site_url('admin/invoices/' . $inv->id) ?>" class="btn btn-sm btn-outline-primary">View</a></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</div>

<?= $this->endSection() ?>
