<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>تقييم: <?= e($profile->first_name_ar . ' ' . $profile->last_name_ar) ?><?php $__template->endSection(); ?>
<?php $__template->section('page_actions'); ?><a href="/hr/performance/reviews/<?= (int) $review->id ?>" class="btn btn-secondary">رجوع</a><?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>
<?php
$criteria = [
    'quality' => 'جودة العمل',
    'productivity' => 'الإنتاجية',
    'attendance' => 'الانتظام والحضور',
    'teamwork' => 'العمل الجماعي',
    'initiative' => 'المبادرة والإبداع',
    'communication' => 'التواصل',
    'leadership' => 'القيادة',
    'technical' => 'المهارات الفنية',
];
$existingScores = json_decode($review->scores_json ?? '{}', true);
?>
<form method="POST" action="/hr/performance/reviews/<?= (int) $review->id ?>">
    <?= csrf_field() ?>
    <div class="card" style="margin-bottom:20px;">
        <div style="padding:16px;border-bottom:1px solid #E5E7EB;">
            <h3 style="margin:0;font-size:16px;">معايير التقييم</h3>
            <p style="margin:4px 0 0;font-size:13px;color:#6B7280;">قيّم كل معيار من 1 (ضعيف) إلى 5 (ممتاز)</p>
        </div>
        <div style="padding:16px;">
            <?php foreach ($criteria as $key => $label): ?>
            <div style="display:flex;justify-content:space-between;align-items:center;padding:12px 0;border-bottom:1px solid #F3F4F6;">
                <label style="font-weight:500;"><?= $label ?></label>
                <div style="display:flex;gap:8px;">
                    <?php for ($i = 1; $i <= 5; $i++): ?>
                    <label style="display:flex;flex-direction:column;align-items:center;cursor:pointer;gap:2px;">
                        <input type="radio" name="scores[<?= $key ?>]" value="<?= $i ?>" <?= (int) ($existingScores[$key] ?? 0) === $i ? 'checked' : '' ?> style="accent-color:#2563EB;">
                        <span style="font-size:11px;color:#6B7280;"><?= $i ?></span>
                    </label>
                    <?php endfor; ?>
                </div>
            </div>
            <?php endforeach; ?>
        </div>
    </div>

    <div class="card" style="margin-bottom:20px;">
        <div style="padding:16px;display:grid;grid-template-columns:repeat(auto-fit,minmax(250px,1fr));gap:16px;">
            <div><label style="display:block;margin-bottom:4px;font-size:13px;font-weight:600;">التقييم العام <span style="color:#DC2626;">*</span></label>
                <select name="overall_rating" class="form-control" required>
                    <option value="">-- اختر --</option>
                    <option value="1" <?= (float) ($review->overall_rating ?? 0) == 1 ? 'selected' : '' ?>>1 - ضعيف</option>
                    <option value="2" <?= (float) ($review->overall_rating ?? 0) == 2 ? 'selected' : '' ?>>2 - مقبول</option>
                    <option value="3" <?= (float) ($review->overall_rating ?? 0) == 3 ? 'selected' : '' ?>>3 - جيد</option>
                    <option value="4" <?= (float) ($review->overall_rating ?? 0) == 4 ? 'selected' : '' ?>>4 - جيد جداً</option>
                    <option value="5" <?= (float) ($review->overall_rating ?? 0) == 5 ? 'selected' : '' ?>>5 - ممتاز</option>
                </select>
            </div>
        </div>
    </div>

    <div class="card" style="margin-bottom:20px;">
        <div style="padding:16px;display:grid;grid-template-columns:repeat(auto-fit,minmax(250px,1fr));gap:16px;">
            <div><label style="display:block;margin-bottom:4px;font-size:13px;">نقاط القوة</label><textarea name="strengths" class="form-control" rows="3"><?= e(old('strengths') ?? ($review->strengths ?? '')) ?></textarea></div>
            <div><label style="display:block;margin-bottom:4px;font-size:13px;">مجالات التحسين</label><textarea name="improvements" class="form-control" rows="3"><?= e(old('improvements') ?? ($review->improvements ?? '')) ?></textarea></div>
            <div><label style="display:block;margin-bottom:4px;font-size:13px;">الأهداف للفترة القادمة</label><textarea name="goals" class="form-control" rows="3"><?= e(old('goals') ?? (($review->goals_json ? json_decode($review->goals_json, true) : '') ?: '')) ?></textarea></div>
            <div><label style="display:block;margin-bottom:4px;font-size:13px;">ملاحظات المقيّم</label><textarea name="notes" class="form-control" rows="3"><?= e(old('notes') ?? ($review->notes ?? '')) ?></textarea></div>
        </div>
    </div>

    <div style="display:flex;gap:10px;justify-content:flex-end;">
        <a href="/hr/performance/reviews/<?= (int) $review->id ?>" class="btn btn-secondary">إلغاء</a>
        <button type="submit" class="btn btn-primary">حفظ التقييم</button>
    </div>
</form>
<?php $__template->endSection(); ?>
