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

<div class="d-flex justify-content-between align-items-center mb-3">
    <p class="text-muted mb-0">Payroll runs and staff payslips — record-keeping only, the hotel pays staff through its own existing means.</p>
    <a href="<?= site_url('payroll/new') ?>" class="btn btn-primary btn-sm"><i class="bi bi-plus-lg me-1"></i>New Payroll Run</a>
</div>

<div class="card">
    <div class="table-responsive">
        <table class="table mb-0 align-middle small">
            <thead><tr><th>Pay Period</th><th>Status</th><th>Staff</th><th class="text-end">Total Net Pay</th><th>Created</th><th></th></tr></thead>
            <tbody>
            <?php if (empty($runs)): ?>
                <tr><td colspan="6" class="text-center text-muted py-4">No payroll runs yet.</td></tr>
            <?php endif; ?>
            <?php foreach ($runs as $run):
                $status  = $lookups->payrollRunStatuses[$run->status] ?? ['label' => ucfirst($run->status), 'badge' => 'secondary'];
                $summary = $summaries[$run->id];
            ?>
                <tr>
                    <td class="fw-semibold"><?= esc(date('F Y', strtotime($run->period_month))) ?></td>
                    <td><span class="badge bg-<?= $status['badge'] ?>"><?= esc($status['label']) ?></span></td>
                    <td><?= (int) $summary['count'] ?></td>
                    <td class="text-end"><?= format_money($summary['total']) ?></td>
                    <td class="text-muted"><?= esc(date('d M Y', strtotime($run->created_at))) ?></td>
                    <td class="text-end"><a href="<?= site_url('payroll/' . $run->id) ?>" class="btn btn-sm btn-outline-secondary"><i class="bi bi-eye"></i></a></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</div>

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