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

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

<?php
$formatMins = static function (int $mins): string {
    $h = intdiv($mins, 60);
    $m = $mins % 60;
    return $h > 0 ? "{$h}h {$m}m" : "{$m}m";
};
?>

<?= view('partials/workspace_hero', [
    'workspaceCrumbPill'    => 'Reports',
    'workspaceCrumbCurrent' => 'Overtime',
    'workspaceTitle'        => 'Overtime Report',
    'workspaceDesc'         => 'Extra hours worked beyond shift end plus overtime threshold.',
]) ?>

<?= $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 Out</th>
                        <th>Overtime</th>
                        <th>Work Time</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_out'] ? esc(date('h:i A', strtotime($r['clock_out']))) : '—' ?></td>
                            <td class="text-primary fw-semibold"><?= $formatMins((int) $r['overtime_minutes']) ?></td>
                            <td><?= $formatMins((int) $r['work_minutes']) ?></td>
                        </tr>
                    <?php endforeach; ?>
                    <?php if (count($records) === 0): ?>
                        <tr><td colspan="6" class="text-center text-muted py-5">No overtime recorded in this period.</td></tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

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