<?php $__template->layout('Layout.main'); ?>
<?php $mn = [1=>'يناير',2=>'فبراير',3=>'مارس',4=>'أبريل',5=>'مايو',6=>'يونيو',7=>'يوليو',8=>'أغسطس',9=>'سبتمبر',10=>'أكتوبر',11=>'نوفمبر',12=>'ديسمبر']; ?>
<?php $__template->section('title'); ?>ملخص الحضور - <?= e($mn[$month] ?? '') ?> <?= $year ?><?php $__template->endSection(); ?>
<?php $__template->section('page_actions'); ?><a href="/hr/reports" class="btn btn-secondary">رجوع</a><?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>
<div class="card" style="margin-bottom:20px;">
    <form method="GET" action="/hr/reports/attendance-summary" style="display:flex;gap:10px;flex-wrap:wrap;align-items:end;padding:16px;">
        <div><label style="display:block;margin-bottom:4px;font-size:13px;">السنة</label><input type="number" name="year" value="<?= $year ?>" class="form-control" style="max-width:100px;"></div>
        <div><label style="display:block;margin-bottom:4px;font-size:13px;">الشهر</label>
            <select name="month" class="form-control">
                <?php foreach ($mn as $k => $v): ?><option value="<?= $k ?>" <?= $month === $k ? 'selected' : '' ?>><?= $v ?></option><?php endforeach; ?>
            </select>
        </div>
        <div><label style="display:block;margin-bottom:4px;font-size:13px;">القسم</label>
            <select name="department_id" class="form-control">
                <option value="">الكل</option>
                <?php foreach ($departments as $d): ?><option value="<?= (int) $d['id'] ?>" <?= $departmentId === (int) $d['id'] ? 'selected' : '' ?>><?= e($d['name_ar']) ?></option><?php endforeach; ?>
            </select>
        </div>
        <button type="submit" class="btn btn-secondary">عرض</button>
    </form>
</div>
<div class="card">
    <div class="table-responsive">
        <table class="data-table">
            <thead><tr><th>الرقم</th><th>الموظف</th><th>القسم</th><th>أيام حضور</th><th>أيام غياب</th><th>أيام تأخير</th><th>إجمالي الساعات</th><th>ساعات إضافية</th></tr></thead>
            <tbody>
                <?php if (empty($records)): ?>
                <tr><td colspan="8" style="text-align:center;padding:40px;color:#9CA3AF;">لا توجد بيانات</td></tr>
                <?php else: ?>
                <?php foreach ($records as $r): ?>
                <tr>
                    <td><?= e($r['employee_number'] ?? '-') ?></td>
                    <td><a href="/hr/employees/<?= (int) $r['id'] ?>"><?= e($r['first_name_ar'] . ' ' . $r['last_name_ar']) ?></a></td>
                    <td><?= e($r['department_name'] ?? '-') ?></td>
                    <td style="color:#059669;font-weight:600;"><?= (int) ($r['present_days'] ?? 0) ?></td>
                    <td style="<?= (int) ($r['absent_days'] ?? 0) > 0 ? 'color:#DC2626;font-weight:600;' : '' ?>"><?= (int) ($r['absent_days'] ?? 0) ?></td>
                    <td style="<?= (int) ($r['late_days'] ?? 0) > 0 ? 'color:#D97706;font-weight:600;' : '' ?>"><?= (int) ($r['late_days'] ?? 0) ?></td>
                    <td><?= number_format((float) ($r['total_hours'] ?? 0), 1) ?></td>
                    <td><?= number_format((float) ($r['total_overtime'] ?? 0), 1) ?></td>
                </tr>
                <?php endforeach; ?>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>
<?php $__template->endSection(); ?>
