<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>المسميات الوظيفية<?php $__template->endSection(); ?>

<?php $__template->section('page_actions'); ?>
<?php if (can('hr.department.manage')): ?>
<a href="/hr/job-titles/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" style="margin-bottom:20px;">
    <form method="GET" action="/hr/job-titles" style="display:flex;gap:10px;flex-wrap:wrap;align-items:end;padding:16px;">
        <div style="flex:1;min-width:200px;">
            <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>
        <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($jobTitles)): ?>
                <tr><td colspan="7" style="text-align:center;padding:40px;color:#9CA3AF;">لا توجد مسميات وظيفية</td></tr>
                <?php else: ?>
                <?php foreach ($jobTitles as $jt): ?>
                <tr>
                    <td><code><?= e($jt['title_code']) ?></code></td>
                    <td><?= e($jt['name_ar']) ?></td>
                    <td><?= $jt['grade_level'] ? (int) $jt['grade_level'] : '-' ?></td>
                    <td><?= $jt['min_salary'] ? number_format((float) $jt['min_salary'], 2) : '-' ?></td>
                    <td><?= $jt['max_salary'] ? number_format((float) $jt['max_salary'], 2) : '-' ?></td>
                    <td>
                        <?php if ($jt['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>
                        <?php if (can('hr.department.manage')): ?>
                        <a href="/hr/job-titles/<?= (int) $jt['id'] ?>/edit" title="تعديل" style="color:#2563EB;">
                            <i data-lucide="edit" style="width:16px;height:16px;"></i>
                        </a>
                        <?php endif; ?>
                    </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(); ?>
