<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>دورات التقييم<?php $__template->endSection(); ?>
<?php $__template->section('page_actions'); ?><a href="/hr/performance" class="btn btn-secondary">رجوع</a><?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>
<?php $csl = ['draft'=>'مسودة','active'=>'نشطة','review'=>'تحت المراجعة','closed'=>'مغلقة']; ?>
<?php $csc = ['draft'=>'#FEF3C7;color:#92400E','active'=>'#D1FAE5;color:#065F46','review'=>'#DBEAFE;color:#1E40AF','closed'=>'#E5E7EB;color:#374151']; ?>

<div class="card" style="margin-bottom:20px;">
    <div style="padding:16px;border-bottom:1px solid #E5E7EB;"><h3 style="margin:0;font-size:16px;">إنشاء دورة تقييم جديدة</h3></div>
    <form method="POST" action="/hr/performance/cycles" style="padding:16px;">
        <?= csrf_field() ?>
        <div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(200px,1fr));gap:12px;margin-bottom:12px;">
            <div><label style="display:block;margin-bottom:4px;font-size:13px;">اسم الدورة <span style="color:#DC2626;">*</span></label><input type="text" name="name_ar" value="<?= e(old('name_ar') ?? '') ?>" class="form-control" placeholder="مثال: تقييم الأداء 2026" required></div>
            <div><label style="display:block;margin-bottom:4px;font-size:13px;">النوع</label>
                <select name="period_type" class="form-control">
                    <option value="annual" <?= old('period_type') === 'annual' ? 'selected' : '' ?>>سنوي</option>
                    <option value="semi_annual" <?= old('period_type') === 'semi_annual' ? 'selected' : '' ?>>نصف سنوي</option>
                    <option value="quarterly" <?= old('period_type') === 'quarterly' ? 'selected' : '' ?>>ربع سنوي</option>
                </select>
            </div>
            <div><label style="display:block;margin-bottom:4px;font-size:13px;">تاريخ البداية <span style="color:#DC2626;">*</span></label><input type="date" name="start_date" value="<?= e(old('start_date') ?? '') ?>" class="form-control" required></div>
            <div><label style="display:block;margin-bottom:4px;font-size:13px;">تاريخ النهاية <span style="color:#DC2626;">*</span></label><input type="date" name="end_date" value="<?= e(old('end_date') ?? '') ?>" class="form-control" required></div>
        </div>
        <button type="submit" class="btn btn-primary">إنشاء الدورة</button>
        <span style="font-size:12px;color:#6B7280;margin-right:8px;">* سيتم إنشاء تقييم تلقائي لكل موظف نشط</span>
    </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($cycles)): ?>
                <tr><td colspan="7" style="text-align:center;padding:40px;color:#9CA3AF;">لا توجد دورات تقييم</td></tr>
                <?php else: ?>
                <?php foreach ($cycles as $c): ?>
                <tr>
                    <td style="font-weight:600;"><?= e($c['name_ar']) ?></td>
                    <td><?= $c['period_type'] === 'annual' ? 'سنوي' : ($c['period_type'] === 'semi_annual' ? 'نصف سنوي' : 'ربع سنوي') ?></td>
                    <td><?= e($c['start_date']) ?> - <?= e($c['end_date']) ?></td>
                    <td><?= (int) ($c['review_count'] ?? 0) ?></td>
                    <td><?php if ($c['avg_rating']): ?><span style="font-weight:600;color:#D97706;"><?= number_format((float) $c['avg_rating'], 1) ?>/5</span><?php else: ?>-<?php endif; ?></td>
                    <td><span style="display:inline-block;padding:2px 8px;border-radius:9999px;font-size:12px;background:<?= $csc[$c['status']] ?? '#E5E7EB;color:#374151' ?>;"><?= e($csl[$c['status']] ?? $c['status']) ?></span></td>
                    <td><a href="/hr/performance/cycles/<?= (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(); ?>
