<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>تسجيل الحضور اليومي: <?= e($date) ?><?php $__template->endSection(); ?>
<?php $__template->section('page_actions'); ?><a href="/hr/attendance" class="btn btn-secondary">رجوع</a><?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>
<div class="card" style="margin-bottom:20px;">
    <form method="GET" action="/hr/attendance/daily" style="display:flex;gap:10px;align-items:end;padding:16px;">
        <div><label style="display:block;margin-bottom:4px;font-size:13px;">التاريخ</label><input type="date" name="date" value="<?= e($date) ?>" class="form-control"></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 == $d['id'] ? 'selected' : '' ?>><?= e($d['name_ar']) ?></option><?php endforeach; ?>
            </select>
        </div>
        <button type="submit" class="btn btn-secondary">عرض</button>
    </form>
</div>
<form method="POST" action="/hr/attendance/daily">
    <?= csrf_field() ?>
    <input type="hidden" name="date" value="<?= e($date) ?>">
    <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></tr></thead>
                <tbody>
                    <?php foreach ($employees as $emp): ?>
                    <tr>
                        <td><code><?= e($emp['employee_number']) ?></code></td>
                        <td><?= e($emp['first_name_ar'] . ' ' . $emp['last_name_ar']) ?></td>
                        <td><?= e($emp['department_name'] ?? '-') ?></td>
                        <td><input type="time" name="attendance[<?= (int) $emp['id'] ?>][check_in]" value="<?= e($emp['check_in_time'] ?? '') ?>" class="form-control" style="max-width:130px;"></td>
                        <td><input type="time" name="attendance[<?= (int) $emp['id'] ?>][check_out]" value="<?= e($emp['check_out_time'] ?? '') ?>" class="form-control" style="max-width:130px;"></td>
                        <td>
                            <?php if ($emp['attendance_id']): ?>
                            <?php $sl = ['present' => 'حاضر', 'absent' => 'غائب', 'late' => 'متأخر']; ?>
                            <span style="font-size:12px;"><?= e($sl[$emp['status']] ?? $emp['status'] ?? '-') ?> (<?= number_format((float) ($emp['actual_hours'] ?? 0), 1) ?>h)</span>
                            <?php else: ?>
                            <span style="color:#9CA3AF;font-size:12px;">لم يسجل</span>
                            <?php endif; ?>
                        </td>
                    </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </div>
        <div style="padding:12px;border-top:1px solid #E5E7EB;display:flex;justify-content:flex-end;">
            <?php if (can('hr.attendance.manage')): ?>
            <button type="submit" class="btn btn-primary">حفظ الحضور</button>
            <?php endif; ?>
        </div>
    </div>
</form>
<?php $__template->endSection(); ?>
