<?php $__template->layout('Layout.main'); ?>
<?php $monthNames = [1=>'يناير',2=>'فبراير',3=>'مارس',4=>'أبريل',5=>'مايو',6=>'يونيو',7=>'يوليو',8=>'أغسطس',9=>'سبتمبر',10=>'أكتوبر',11=>'نوفمبر',12=>'ديسمبر']; ?>
<?php $__template->section('title'); ?>حضور <?= e($profile->first_name_ar . ' ' . $profile->last_name_ar) ?> - <?= e($monthNames[$month] ?? '') ?> <?= $year ?><?php $__template->endSection(); ?>
<?php $__template->section('page_actions'); ?><a href="/hr/employees/<?= (int) $profile->id ?>" class="btn btn-secondary">ملف الموظف</a><?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>
<?php if ($summary): ?>
<div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(140px,1fr));gap:12px;margin-bottom:20px;">
    <div class="card" style="padding:16px;text-align:center;"><div style="font-size:24px;font-weight:700;color:#059669;"><?= (int) ($summary['present_days'] ?? 0) ?></div><div style="font-size:13px;color:#6B7280;">أيام الحضور</div></div>
    <div class="card" style="padding:16px;text-align:center;"><div style="font-size:24px;font-weight:700;color:#DC2626;"><?= (int) ($summary['absent_days'] ?? 0) ?></div><div style="font-size:13px;color:#6B7280;">أيام الغياب</div></div>
    <div class="card" style="padding:16px;text-align:center;"><div style="font-size:24px;font-weight:700;color:#D97706;"><?= (int) ($summary['late_days'] ?? 0) ?></div><div style="font-size:13px;color:#6B7280;">أيام التأخير</div></div>
    <div class="card" style="padding:16px;text-align:center;"><div style="font-size:24px;font-weight:700;"><?= number_format((float) ($summary['total_hours'] ?? 0), 1) ?></div><div style="font-size:13px;color:#6B7280;">إجمالي الساعات</div></div>
    <div class="card" style="padding:16px;text-align:center;"><div style="font-size:24px;font-weight:700;color:#2563EB;"><?= number_format((float) ($summary['total_overtime'] ?? 0), 1) ?></div><div style="font-size:13px;color:#6B7280;">ساعات إضافية</div></div>
</div>
<?php endif; ?>
<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></tr></thead>
            <tbody>
                <?php if (empty($records)): ?>
                <tr><td colspan="7" style="text-align:center;padding:40px;color:#9CA3AF;">لا توجد سجلات</td></tr>
                <?php else: ?>
                <?php $dayNames = ['Saturday'=>'السبت','Sunday'=>'الأحد','Monday'=>'الاثنين','Tuesday'=>'الثلاثاء','Wednesday'=>'الأربعاء','Thursday'=>'الخميس','Friday'=>'الجمعة']; ?>
                <?php foreach ($records as $r): ?>
                <?php $dayEn = date('l', strtotime($r['attendance_date'])); ?>
                <tr>
                    <td><?= e($r['attendance_date']) ?></td>
                    <td><?= e($dayNames[$dayEn] ?? $dayEn) ?></td>
                    <td><?= e($r['check_in_time'] ?? '-') ?></td>
                    <td><?= e($r['check_out_time'] ?? '-') ?></td>
                    <td><?= number_format((float) ($r['actual_hours'] ?? 0), 1) ?></td>
                    <td><?= number_format((float) ($r['overtime_hours'] ?? 0), 1) ?></td>
                    <td>
                        <?php $sl = ['present'=>'حاضر','absent'=>'غائب','late'=>'متأخر','leave'=>'إجازة','holiday'=>'عطلة','rest_day'=>'يوم راحة','half_day'=>'نصف يوم']; ?>
                        <?php $sc = ['present'=>'#DEF7EC;color:#03543F','absent'=>'#FDE8E8;color:#9B1C1C','late'=>'#FEF3C7;color:#92400E','leave'=>'#DBEAFE;color:#1E40AF','holiday'=>'#E5E7EB;color:#374151','rest_day'=>'#E5E7EB;color:#374151','half_day'=>'#FEF3C7;color:#92400E']; ?>
                        <span style="display:inline-block;padding:2px 8px;border-radius:9999px;font-size:12px;background:<?= $sc[$r['status']] ?? '#E5E7EB;color:#374151' ?>;"><?= e($sl[$r['status']] ?? $r['status']) ?></span>
                    </td>
                </tr>
                <?php endforeach; ?>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>
<?php $__template->endSection(); ?>
