<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>العقود المنتهية / القاربة على الانتهاء<?php $__template->endSection(); ?>
<?php $__template->section('page_actions'); ?><a href="/hr/reports" class="btn btn-secondary">رجوع</a><?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>
<div class="card" style="margin-bottom:20px;">
    <form method="GET" action="/hr/reports/contract-expiry" style="display:flex;gap:10px;align-items:end;padding:16px;">
        <div><label style="display:block;margin-bottom:4px;font-size:13px;">خلال (أيام)</label>
            <select name="days" class="form-control">
                <option value="7" <?= $days === 7 ? 'selected' : '' ?>>7 أيام</option>
                <option value="15" <?= $days === 15 ? 'selected' : '' ?>>15 يوم</option>
                <option value="30" <?= $days === 30 ? 'selected' : '' ?>>30 يوم</option>
                <option value="60" <?= $days === 60 ? 'selected' : '' ?>>60 يوم</option>
                <option value="90" <?= $days === 90 ? 'selected' : '' ?>>90 يوم</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;">لا توجد عقود منتهية أو قاربة على الانتهاء خلال <?= $days ?> يوم</td></tr>
                <?php else: ?>
                <?php foreach ($contracts as $c): ?>
                <?php $daysRem = (int) ($c['days_remaining'] ?? 0); ?>
                <tr>
                    <td><a href="/hr/employees/<?= (int) $c['employee_profile_id'] ?>"><?= e($c['first_name_ar'] . ' ' . $c['last_name_ar']) ?></a></td>
                    <td><?= e($c['employee_number'] ?? '-') ?></td>
                    <td><?= e($c['department_name'] ?? '-') ?></td>
                    <td><?= e($c['start_date'] ?? '-') ?></td>
                    <td><?= e($c['end_date'] ?? '-') ?></td>
                    <td>
                        <?php if ($daysRem < 0): ?>
                        <span style="color:#DC2626;font-weight:700;">منتهي منذ <?= abs($daysRem) ?> يوم</span>
                        <?php elseif ($daysRem === 0): ?>
                        <span style="color:#DC2626;font-weight:700;">ينتهي اليوم</span>
                        <?php elseif ($daysRem <= 7): ?>
                        <span style="color:#DC2626;font-weight:600;"><?= $daysRem ?> يوم</span>
                        <?php elseif ($daysRem <= 30): ?>
                        <span style="color:#D97706;font-weight:600;"><?= $daysRem ?> يوم</span>
                        <?php else: ?>
                        <span><?= $daysRem ?> يوم</span>
                        <?php endif; ?>
                    </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>
</div>
<script>if(typeof lucide!=='undefined')lucide.createIcons();</script>
<?php $__template->endSection(); ?>
