<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>العقود<?php $__template->endSection(); ?>

<?php $__template->section('page_actions'); ?>
<?php if (can('hr.contract.manage')): ?>
<a href="/hr/contracts/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/contracts" 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>
        <div style="min-width:140px;">
            <label style="display:block;margin-bottom:4px;font-size:13px;color:#6B7280;">الحالة</label>
            <select name="status" class="form-control">
                <option value="">الكل</option>
                <option value="draft" <?= $filters['status'] === 'draft' ? 'selected' : '' ?>>مسودة</option>
                <option value="active" <?= $filters['status'] === 'active' ? 'selected' : '' ?>>نشط</option>
                <option value="expired" <?= $filters['status'] === 'expired' ? 'selected' : '' ?>>منتهي</option>
                <option value="terminated" <?= $filters['status'] === 'terminated' ? 'selected' : '' ?>>منهي</option>
            </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($contracts)): ?>
                <tr><td colspan="7" style="text-align:center;padding:40px;color:#9CA3AF;">لا توجد عقود</td></tr>
                <?php else: ?>
                <?php foreach ($contracts as $c): ?>
                <?php $statusLabels = ['draft' => 'مسودة', 'active' => 'نشط', 'expired' => 'منتهي', 'terminated' => 'منهي', 'renewed' => 'مجدد']; ?>
                <?php $statusColors = ['draft' => '#E5E7EB;color:#374151', 'active' => '#DEF7EC;color:#03543F', 'expired' => '#FEF3C7;color:#92400E', 'terminated' => '#FDE8E8;color:#9B1C1C', 'renewed' => '#DBEAFE;color:#1E40AF']; ?>
                <tr>
                    <td><a href="/hr/contracts/<?= (int) $c['id'] ?>"><?= e($c['contract_number']) ?></a></td>
                    <td><?= e($c['full_name_ar'] ?? '') ?></td>
                    <td><?= $c['contract_type'] === 'definite' ? 'محدد المدة' : 'غير محدد' ?></td>
                    <td><?= e($c['start_date']) ?></td>
                    <td><?= e($c['end_date'] ?? '-') ?></td>
                    <td><span style="display:inline-block;padding:2px 8px;border-radius:9999px;font-size:12px;background:<?= $statusColors[$c['status']] ?? '#E5E7EB;color:#374151' ?>;"><?= e($statusLabels[$c['status']] ?? $c['status']) ?></span></td>
                    <td><a href="/hr/contracts/<?= (int) $c['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(); ?>
