<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>أنواع الإجازات<?php $__template->endSection(); ?>

<?php $__template->section('page_actions'); ?>
<?php if (can('hr.leave.manage')): ?>
<a href="/hr/leave-types/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 endif; ?>
<?php $__template->endSection(); ?>

<?php $__template->section('content'); ?>
<div class="card">
    <div class="table-responsive">
        <table class="data-table">
            <thead>
                <tr>
                    <th style="width:50px;">#</th>
                    <th>الكود</th>
                    <th>الاسم</th>
                    <th>التصنيف</th>
                    <th>الأيام/سنة</th>
                    <th>مدفوعة</th>
                    <th>نسبة الراتب</th>
                    <th>الجنس</th>
                    <th>ترحيل</th>
                    <th>الحالة</th>
                    <th>إجراءات</th>
                </tr>
            </thead>
            <tbody>
                <?php if (empty($types)): ?>
                <tr><td colspan="11" style="text-align:center;padding:40px;color:#9CA3AF;">لا يوجد أنواع إجازات</td></tr>
                <?php else: ?>
                <?php foreach ($types as $type): ?>
                <tr>
                    <td><?= (int) $type['sort_order'] ?></td>
                    <td><code style="font-size:12px;background:#F3F4F6;padding:2px 6px;border-radius:4px;"><?= e($type['code']) ?></code></td>
                    <td><a href="/hr/leave-types/<?= (int) $type['id'] ?>"><?= e($type['name_ar']) ?></a></td>
                    <td><?= e($categories[$type['category'] ?? ''] ?? '-') ?></td>
                    <td><?= $type['default_days_per_year'] !== null ? number_format((float)$type['default_days_per_year'], 1) : '-' ?></td>
                    <td>
                        <?php if ((int) $type['is_paid']): ?>
                        <span style="color:#059669;">✓ مدفوعة</span>
                        <?php else: ?>
                        <span style="color:#DC2626;">✗ بدون راتب</span>
                        <?php endif; ?>
                    </td>
                    <td><?= number_format((float)$type['pay_percentage'], 0) ?>%</td>
                    <td>
                        <?php
                        $genderMap = ['male' => 'ذكور فقط', 'female' => 'إناث فقط'];
                        echo e($genderMap[$type['gender_restriction'] ?? ''] ?? 'الكل');
                        ?>
                    </td>
                    <td>
                        <?php if ((int) $type['carry_over_allowed']): ?>
                        <span style="color:#059669;">✓</span>
                        <?php else: ?>
                        <span style="color:#9CA3AF;">—</span>
                        <?php endif; ?>
                    </td>
                    <td>
                        <?php if ((int) $type['is_active']): ?>
                        <span style="display:inline-block;padding:2px 8px;border-radius:9999px;font-size:12px;background:#DEF7EC;color:#03543F;">مفعّل</span>
                        <?php else: ?>
                        <span style="display:inline-block;padding:2px 8px;border-radius:9999px;font-size:12px;background:#FDE8E8;color:#9B1C1C;">معطّل</span>
                        <?php endif; ?>
                    </td>
                    <td style="white-space:nowrap;">
                        <a href="/hr/leave-types/<?= (int) $type['id'] ?>" title="عرض" style="color:#2563EB;margin-inline-end:8px;"><i data-lucide="eye" style="width:16px;height:16px;"></i></a>
                        <a href="/hr/leave-types/<?= (int) $type['id'] ?>/edit" title="تعديل" style="color:#059669;"><i data-lucide="edit" style="width:16px;height:16px;"></i></a>
                    </td>
                </tr>
                <?php endforeach; ?>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>
<script>if(typeof lucide!=='undefined')lucide.createIcons();</script>
<?php $__template->endSection(); ?>
