<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>تقييم اللاعبين — المدربين<?php $__template->endSection(); ?>

<?php $__template->section('content'); ?>

<div class="card" style="margin-bottom:16px;">
    <div style="padding:16px 20px;border-bottom:1px solid #E5E7EB;display:flex;align-items:center;gap:8px;flex-wrap:wrap;">
        <i data-lucide="clipboard-check" style="width:20px;height:20px;color:#0D7377;"></i>
        <h3 style="margin:0;color:#0D7377;font-size:16px;">لاعبين في انتظار التقييم الفني</h3>
        <span style="background:#FEF3C7;color:#92400E;padding:3px 10px;border-radius:12px;font-size:12px;font-weight:700;"><?= count($players) ?></span>
        <form method="GET" style="margin-right:auto;display:flex;align-items:center;gap:8px;">
            <select name="discipline_id" class="form-input" style="padding:6px 12px;font-size:13px;border-radius:8px;min-width:140px;" onchange="this.form.submit()">
                <option value="">كل الأنشطة</option>
                <?php foreach ($disciplines as $d): ?>
                <option value="<?= (int) $d['id'] ?>" <?= ($filterDiscipline ?? 0) == (int) $d['id'] ? 'selected' : '' ?>><?= e($d['name_ar']) ?></option>
                <?php endforeach; ?>
            </select>
        </form>
    </div>

    <?php if (empty($players)): ?>
    <div style="padding:60px 24px;text-align:center;color:#6B7280;">
        <i data-lucide="check-circle" style="width:48px;height:48px;color:#D1D5DB;display:block;margin:0 auto 15px;"></i>
        <div style="font-size:15px;">لا يوجد لاعبين في انتظار التقييم</div>
        <div style="font-size:13px;margin-top:8px;">جميع اللاعبين المسجلين تم تعيينهم في مجموعات</div>
    </div>
    <?php else: ?>
    <div style="overflow-x:auto;">
        <table style="width:100%;border-collapse:collapse;font-size:14px;">
            <thead>
                <tr style="background:#F9FAFB;border-bottom:1px solid #E5E7EB;">
                    <th style="padding:12px 16px;text-align:right;font-weight:600;color:#374151;">اللاعب</th>
                    <th style="padding:12px 16px;text-align:right;font-weight:600;color:#374151;">النوع</th>
                    <th style="padding:12px 16px;text-align:right;font-weight:600;color:#374151;">الأنشطة المطلوبة</th>
                    <th style="padding:12px 16px;text-align:right;font-weight:600;color:#374151;">تاريخ التسجيل</th>
                    <th style="padding:12px 16px;text-align:center;font-weight:600;color:#374151;">إجراء</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($players as $p): ?>
                <tr style="border-bottom:1px solid #F3F4F6;">
                    <td style="padding:12px 16px;">
                        <div style="display:flex;align-items:center;gap:10px;">
                            <div style="width:40px;height:40px;border-radius:8px;overflow:hidden;background:#F3F4F6;flex-shrink:0;">
                                <?php if (!empty($p['photo_path'])): ?>
                                <img src="/<?= e($p['photo_path']) ?>" style="width:100%;height:100%;object-fit:cover;">
                                <?php else: ?>
                                <div style="width:100%;height:100%;display:flex;align-items:center;justify-content:center;color:#9CA3AF;"><i data-lucide="user" style="width:18px;height:18px;"></i></div>
                                <?php endif; ?>
                            </div>
                            <div>
                                <div style="font-weight:600;"><?= e($p['full_name_ar']) ?></div>
                                <div style="font-size:12px;color:#6B7280;"><?= e($p['national_id'] ?? '—') ?></div>
                            </div>
                        </div>
                    </td>
                    <td style="padding:12px 16px;">
                        <span style="padding:3px 8px;border-radius:6px;font-size:11px;font-weight:600;background:<?= $p['player_type'] === 'member' ? '#ECFDF5' : '#FEF3C7' ?>;color:<?= $p['player_type'] === 'member' ? '#059669' : '#D97706' ?>;">
                            <?= $p['player_type'] === 'member' ? 'عضو' : 'غير عضو' ?>
                        </span>
                    </td>
                    <td style="padding:12px 16px;">
                        <?php
                        $disciplines = [];
                        if (!empty($p['selected_disciplines'])) {
                            $decoded = json_decode($p['selected_disciplines'], true);
                            if (is_array($decoded)) {
                                $disciplines = $decoded;
                            }
                        }
                        if (!empty($disciplines)):
                            foreach ($disciplines as $disc):
                        ?>
                        <span style="display:inline-block;padding:2px 8px;border-radius:4px;background:#EFF6FF;color:#2563EB;font-size:11px;font-weight:600;margin-left:4px;"><?= e($disc['name'] ?? $disc) ?></span>
                        <?php endforeach; else: ?>
                        <span style="color:#9CA3AF;font-size:12px;">لم يحدد</span>
                        <?php endif; ?>
                    </td>
                    <td style="padding:12px 16px;font-size:13px;color:#6B7280;direction:ltr;text-align:right;">
                        <?= e(substr($p['registration_date'], 0, 10)) ?>
                    </td>
                    <td style="padding:12px 16px;text-align:center;">
                        <a href="/sa/coach-assessment/<?= (int) $p['registration_id'] ?>" class="btn btn-sm btn-primary" style="padding:8px 16px;font-size:13px;">
                            <i data-lucide="clipboard-check" style="width:14px;height:14px;vertical-align:middle;margin-left:4px;"></i> تقييم
                        </a>
                    </td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
    <?php endif; ?>
</div>

<script>
document.addEventListener('DOMContentLoaded', function() {
    if (typeof lucide !== 'undefined') lucide.createIcons();
});
</script>
<?php $__template->endSection(); ?>
