<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>نهاية الخدمة<?php $__template->endSection(); ?>
<?php $__template->section('page_actions'); ?><a href="/hr/end-of-service/create" class="btn btn-primary" style="display:inline-flex;align-items:center;gap:6px;"><i data-lucide="plus" style="width:16px;height:16px;"></i> إنهاء خدمة جديد</a><?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>
<?php $sl = ['draft'=>'مسودة','calculated'=>'تم الحساب','pending_approval'=>'في انتظار الاعتماد','approved'=>'معتمد','paid'=>'تم الصرف','cancelled'=>'ملغى']; ?>
<?php $sc = ['draft'=>'#FEF3C7;color:#92400E','calculated'=>'#DBEAFE;color:#1E40AF','pending_approval'=>'#FDE8E8;color:#9B1C1C','approved'=>'#D1FAE5;color:#065F46','paid'=>'#E5E7EB;color:#374151','cancelled'=>'#E5E7EB;color:#6B7280']; ?>
<?php $tl = ['resignation'=>'استقالة','termination'=>'فصل','end_of_contract'=>'انتهاء عقد','retirement'=>'تقاعد','death'=>'وفاة','disability'=>'عجز','mutual_agreement'=>'اتفاق مشترك']; ?>
<div class="card" style="margin-bottom:20px;">
    <form method="GET" action="/hr/end-of-service" 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>
            <?php foreach ($sl as $k => $v): ?><option value="<?= $k ?>" <?= $filters['status'] === $k ? 'selected' : '' ?>><?= $v ?></option><?php endforeach; ?>
            </select>
        </div>
        <div style="min-width:130px;"><label style="display:block;margin-bottom:4px;font-size:13px;color:#6B7280;">النوع</label>
            <select name="type" class="form-control"><option value="">الكل</option>
            <?php foreach ($tl as $k => $v): ?><option value="<?= $k ?>" <?= $filters['type'] === $k ? 'selected' : '' ?>><?= $v ?></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></tr></thead>
            <tbody>
                <?php if (empty($records)): ?>
                <tr><td colspan="6" style="text-align:center;padding:40px;color:#9CA3AF;">لا توجد سجلات</td></tr>
                <?php else: ?>
                <?php foreach ($records as $r): ?>
                <tr>
                    <td><a href="/hr/employees/<?= (int) $r['employee_profile_id'] ?>"><?= e($r['full_name_ar'] ?? '-') ?></a></td>
                    <td><?= e($tl[$r['termination_type']] ?? $r['termination_type']) ?></td>
                    <td><?= e($r['effective_date'] ?? '-') ?></td>
                    <td style="font-weight:700;"><?= $r['net_settlement'] !== null ? number_format((float) $r['net_settlement'], 2) . ' ج.م' : '-' ?></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/end-of-service/<?= (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(); ?>
