<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?><?= e($cycle->name_ar) ?><?php $__template->endSection(); ?>
<?php $__template->section('page_actions'); ?><a href="/hr/performance/cycles" 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']; ?>
<?php $rsl = ['pending'=>'بانتظار التقييم','in_progress'=>'قيد التقييم','submitted'=>'تم التقديم','acknowledged'=>'تم الإقرار']; ?>
<?php $rsc = ['pending'=>'#FEF3C7;color:#92400E','in_progress'=>'#FEF3C7;color:#92400E','submitted'=>'#D1FAE5;color:#065F46','acknowledged'=>'#DBEAFE;color:#1E40AF']; ?>

<div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(160px,1fr));gap:12px;margin-bottom:20px;">
    <div class="card" style="padding:16px;text-align:center;"><div style="font-size:13px;color:#6B7280;">الحالة</div><div style="margin-top:4px;"><span style="display:inline-block;padding:2px 8px;border-radius:9999px;font-size:12px;background:<?= $csc[$cycle->status] ?? '#E5E7EB;color:#374151' ?>;"><?= e($csl[$cycle->status] ?? $cycle->status) ?></span></div></div>
    <div class="card" style="padding:16px;text-align:center;"><div style="font-size:13px;color:#6B7280;">إجمالي التقييمات</div><div style="font-size:20px;font-weight:700;"><?= (int) ($stats['total'] ?? 0) ?></div></div>
    <div class="card" style="padding:16px;text-align:center;"><div style="font-size:13px;color:#6B7280;">مكتمل</div><div style="font-size:20px;font-weight:700;color:#059669;"><?= (int) ($stats['completed'] ?? 0) ?></div></div>
    <div class="card" style="padding:16px;text-align:center;"><div style="font-size:13px;color:#6B7280;">بانتظار</div><div style="font-size:20px;font-weight:700;color:#D97706;"><?= (int) ($stats['pending'] ?? 0) ?></div></div>
    <div class="card" style="padding:16px;text-align:center;"><div style="font-size:13px;color:#6B7280;">متوسط التقييم</div><div style="font-size:20px;font-weight:700;color:#2563EB;"><?= $stats['avg_rating'] ? number_format((float) $stats['avg_rating'], 1) . '/5' : '-' ?></div></div>
</div>

<?php
$total = (int) ($stats['total'] ?? 0);
$completed = (int) ($stats['completed'] ?? 0);
$pct = $total > 0 ? round($completed / $total * 100) : 0;
?>
<?php if ($total > 0): ?>
<div class="card" style="margin-bottom:20px;padding:16px;">
    <div style="display:flex;justify-content:space-between;margin-bottom:6px;font-size:13px;"><span>نسبة الإكمال</span><span style="font-weight:600;"><?= $pct ?>%</span></div>
    <div style="height:8px;background:#E5E7EB;border-radius:4px;overflow:hidden;"><div style="height:100%;width:<?= $pct ?>%;background:#2563EB;border-radius:4px;transition:width .3s;"></div></div>
</div>
<?php endif; ?>

<div class="card">
    <div style="padding:16px;border-bottom:1px solid #E5E7EB;"><h3 style="margin:0;font-size:16px;">التقييمات</h3></div>
    <div class="table-responsive">
        <table class="data-table">
            <thead><tr><th>الموظف</th><th>القسم</th><th>التقييم</th><th>الحالة</th><th>إجراءات</th></tr></thead>
            <tbody>
                <?php if (empty($reviews)): ?>
                <tr><td colspan="5" style="text-align:center;padding:40px;color:#9CA3AF;">لا توجد تقييمات</td></tr>
                <?php else: ?>
                <?php foreach ($reviews as $r): ?>
                <tr>
                    <td><a href="/hr/employees/<?= (int) $r['employee_profile_id'] ?>"><?= e($r['full_name_ar'] ?? '') ?></a></td>
                    <td><?= e($r['department_name'] ?? '-') ?></td>
                    <td><?php if ((float) ($r['overall_rating'] ?? 0) > 0): ?>
                        <?php $rating = (float) $r['overall_rating']; $color = $rating >= 4 ? '#059669' : ($rating >= 3 ? '#D97706' : '#DC2626'); ?>
                        <span style="font-weight:700;color:<?= $color ?>;"><?= number_format($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:<?= $rsc[$r['status']] ?? '#E5E7EB;color:#374151' ?>;"><?= e($rsl[$r['status']] ?? $r['status']) ?></span></td>
                    <td style="display:flex;gap:6px;">
                        <a href="/hr/performance/reviews/<?= (int) $r['id'] ?>" style="color:#2563EB;" title="عرض"><i data-lucide="eye" style="width:16px;height:16px;"></i></a>
                        <?php if ($r['status'] !== 'acknowledged'): ?><a href="/hr/performance/reviews/<?= (int) $r['id'] ?>/edit" style="color:#D97706;" title="تقييم"><i data-lucide="edit" style="width:16px;height:16px;"></i></a><?php endif; ?>
                    </td>
                </tr>
                <?php endforeach; ?>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>
<script>if(typeof lucide!=='undefined')lucide.createIcons();</script>
<?php $__template->endSection(); ?>
