<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>طلبات الإجازات<?php $__template->endSection(); ?>
<?php $__template->section('page_actions'); ?>
<a href="/hr/leaves/request" class="btn btn-primary" style="display:inline-flex;align-items:center;gap:6px;"><i data-lucide="plus" style="width:16px;height:16px;"></i> طلب إجازة</a>
<a href="/hr/leaves/balances" class="btn btn-secondary">الأرصدة</a>
<a href="/hr/leaves/calendar" class="btn btn-secondary">التقويم</a>
<?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>
<div class="card" style="margin-bottom:20px;">
    <form method="GET" action="/hr/leaves" style="display:flex;gap:10px;flex-wrap:wrap;align-items:end;padding:16px;">
        <div style="flex:1;min-width:160px;"><label style="display:block;margin-bottom:4px;font-size:13px;color:#6B7280;">بحث</label><input type="text" name="q" value="<?= e($filters['q']) ?>" placeholder="اسم الموظف..." class="form-control"></div>
        <div style="min-width:130px;"><label style="display:block;margin-bottom:4px;font-size:13px;color:#6B7280;">الحالة</label>
            <select name="status" class="form-control"><option value="">الكل</option>
            <option value="pending" <?= $filters['status'] === 'pending' ? 'selected' : '' ?>>معلق</option>
            <option value="approved" <?= $filters['status'] === 'approved' ? 'selected' : '' ?>>موافق</option>
            <option value="rejected" <?= $filters['status'] === 'rejected' ? 'selected' : '' ?>>مرفوض</option>
            </select>
        </div>
        <div style="min-width:130px;"><label style="display:block;margin-bottom:4px;font-size:13px;color:#6B7280;">نوع الإجازة</label>
            <select name="leave_type_id" class="form-control"><option value="">الكل</option>
            <?php foreach ($leaveTypes as $lt): ?><option value="<?= (int) $lt['id'] ?>" <?= $filters['leave_type_id'] == $lt['id'] ? 'selected' : '' ?>><?= e($lt['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></tr></thead>
            <tbody>
                <?php if (empty($requests)): ?>
                <tr><td colspan="7" style="text-align:center;padding:40px;color:#9CA3AF;">لا توجد طلبات</td></tr>
                <?php else: ?>
                <?php foreach ($requests as $r): ?>
                <?php $sl = ['pending'=>'معلق','approved'=>'موافق','rejected'=>'مرفوض','cancelled'=>'ملغي','taken'=>'تم أخذها']; ?>
                <?php $sc = ['pending'=>'#FEF3C7;color:#92400E','approved'=>'#DEF7EC;color:#03543F','rejected'=>'#FDE8E8;color:#9B1C1C','cancelled'=>'#E5E7EB;color:#374151','taken'=>'#DBEAFE;color:#1E40AF']; ?>
                <tr>
                    <td><a href="/hr/employees/<?= (int) $r['employee_profile_id'] ?>"><?= e(($r['first_name_ar'] ?? '') . ' ' . ($r['last_name_ar'] ?? '')) ?></a></td>
                    <td><?= e($r['leave_type_name'] ?? '-') ?></td>
                    <td><?= e($r['start_date']) ?></td>
                    <td><?= e($r['end_date']) ?></td>
                    <td><?= number_format((float) $r['total_days'], 1) ?></td>
                    <td><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>
                    <td><a href="/hr/leaves/<?= (int) $r['id'] ?>" style="color:#2563EB;"><i data-lucide="eye" style="width:16px;height:16px;"></i></a></td>
                </tr>
                <?php endforeach; ?>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
    <?php if (!empty($pagination)): ?><?php $__template->include('Shared.Components.pagination', ['pagination' => $pagination]); ?><?php endif; ?>
</div>
<script>if(typeof lucide!=='undefined')lucide.createIcons();</script>
<?php $__template->endSection(); ?>
