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

<div class="d-flex justify-content-between align-items-start mb-3 flex-wrap gap-2">
    <div>
        <h1 class="h3 mb-1">Staff Performance</h1>
        <p class="text-muted mb-0">Real activity already being tracked, grouped by who did it — not an invented score.</p>
    </div>
    <form action="<?= site_url('reports/staff-performance') ?>" method="get" class="d-flex align-items-center gap-2">
        <input type="date" class="form-control form-control-sm" name="from" value="<?= esc($from) ?>">
        <span class="text-muted small">to</span>
        <input type="date" class="form-control form-control-sm" name="to" value="<?= esc($to) ?>">
        <button type="submit" class="btn btn-sm btn-outline-primary"><i class="bi bi-funnel me-1"></i>Filter</button>
    </form>
</div>

<div class="card shadow-sm">
    <div class="table-scroll">
        <table class="table table-sm align-middle mb-0">
            <thead class="table-light">
                <tr>
                    <th>Staff</th>
                    <th>Role</th>
                    <th class="text-end">Housekeeping Tasks</th>
                    <th class="text-end">Avg Completion</th>
                    <th class="text-end">Maintenance Resolved</th>
                    <th class="text-end">Bookings Created</th>
                    <th class="text-end">Check-Ins Processed</th>
                    <th class="text-end">F&amp;B Orders</th>
                    <th class="text-end">Overtime</th>
                </tr>
            </thead>
            <tbody>
                <?php if (empty($rows)): ?>
                    <tr><td colspan="9" class="text-center text-muted py-4">No staff activity in this date range.</td></tr>
                <?php endif; ?>
                <?php foreach ($rows as $row): ?>
                    <tr>
                        <td class="fw-semibold"><?= esc($row['user']->full_name) ?></td>
                        <td><span class="badge bg-<?= $lookups->staffRoles[$row['user']->role]['badge'] ?? 'secondary' ?>"><?= esc($lookups->staffRoles[$row['user']->role]['label'] ?? $row['user']->role) ?></span></td>
                        <td class="text-end"><?= $row['housekeepingCount'] ?: '—' ?></td>
                        <td class="text-end"><?= $row['housekeepingAvgMinutes'] > 0 ? number_format($row['housekeepingAvgMinutes']) . ' min' : '—' ?></td>
                        <td class="text-end"><?= $row['maintenanceResolved'] ?: '—' ?></td>
                        <td class="text-end"><?= $row['bookingsCreated'] ?: '—' ?></td>
                        <td class="text-end"><?= $row['checkinsProcessed'] ?: '—' ?></td>
                        <td class="text-end"><?= $row['fnbOrders'] ?: '—' ?></td>
                        <td class="text-end"><?= $row['overtimeHours'] > 0 ? number_format($row['overtimeHours'], 1) . 'h' : '—' ?></td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</div>

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