<?= $this->extend('layouts/enterprise') ?>

<?= $this->section('content') ?>

<?php
$reportFilter = function (string $action) use ($filters) {
    $params = http_build_query(array_filter([
        'from'        => $filters['dateFrom'],
        'to'          => $filters['dateTo'],
        'employee_id' => $filters['employeeId'] ?? null,
    ]));
    return base_url("attendance/{$action}?{$params}");
};
?>

<?= view('partials/workspace_hero', [
    'workspaceCrumbPill'    => 'Reports',
    'workspaceCrumbCurrent' => 'Late Arrivals',
    'workspaceTitle'        => 'Late Arrival Report',
    'workspaceDesc'         => 'Employees who arrived after their shift grace period.',
]) ?>

<?= $this->include('Modules\Attendance\Views\reports\_filter') ?>

<div class="enterprise-data-panel">
    <div class="enterprise-data-panel__body">
        <div class="table-responsive">
            <table class="enterprise-data-table">
                <thead>
                    <tr>
                        <th>Date</th>
                        <th>Employee</th>
                        <th>Shift</th>
                        <th>Clock In</th>
                        <th>Late By</th>
                        <th>Status</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($records as $r): ?>
                        <tr>
                            <td><?= esc(date('M j, Y', strtotime($r['attendance_date']))) ?></td>
                            <td>
                                <span class="enterprise-data-table__primary"><?= esc($r['full_name']) ?></span>
                                <br><small class="text-muted"><?= esc($r['employee_number']) ?></small>
                            </td>
                            <td><?= esc($r['shift_name'] ?? '—') ?></td>
                            <td><?= $r['clock_in'] ? esc(date('h:i A', strtotime($r['clock_in']))) : '—' ?></td>
                            <td class="text-warning fw-semibold"><?= esc($r['late_minutes']) ?> min</td>
                            <td><?= esc(ucwords(str_replace('_', ' ', $r['status']))) ?></td>
                        </tr>
                    <?php endforeach; ?>
                    <?php if (count($records) === 0): ?>
                        <tr><td colspan="6" class="text-center text-muted py-5">No late arrivals in this period.</td></tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

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