<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>تعيين اللاعبين في المجموعات<?php $__template->endSection(); ?>

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

<!-- Filters -->
<div class="card" style="padding:15px;margin-bottom:20px;">
    <form method="GET" action="/sa/assignments" style="display:flex;gap:12px;align-items:end;flex-wrap:wrap;">
        <div class="form-group" style="margin:0;min-width:160px;">
            <label class="form-label" style="font-size:12px;">النشاط الرياضي</label>
            <select name="discipline_id" class="form-input" style="font-size:13px;">
                <option value="">الكل</option>
                <?php foreach ($disciplines as $d): ?>
                <option value="<?= (int) $d['id'] ?>" <?= ($filters['discipline_id'] ?? '') == $d['id'] ? 'selected' : '' ?>><?= e($d['name_ar']) ?></option>
                <?php endforeach; ?>
            </select>
        </div>
        <div class="form-group" style="margin:0;min-width:180px;">
            <label class="form-label" style="font-size:12px;">بحث برنامج</label>
            <input type="text" name="program" class="form-input" value="<?= e($filters['program'] ?? '') ?>" placeholder="اسم البرنامج..." style="font-size:13px;">
        </div>
        <div class="form-group" style="margin:0;min-width:130px;">
            <label class="form-label" style="font-size:12px;">الحالة</label>
            <select name="status" class="form-input" style="font-size:13px;">
                <option value="unassigned" <?= ($filters['status'] ?? '') === 'unassigned' ? 'selected' : '' ?>>غير معينين</option>
                <option value="all" <?= ($filters['status'] ?? '') === 'all' ? 'selected' : '' ?>>الكل</option>
            </select>
        </div>
        <button type="submit" class="btn btn-primary" style="font-size:13px;padding:8px 16px;">
            <i data-lucide="filter" style="width:14px;height:14px;vertical-align:middle;margin-left:4px;"></i> تصفية
        </button>
    </form>
</div>

<!-- Players Table -->
<div class="card">
    <div class="table-responsive">
        <table class="data-table">
            <thead>
                <tr>
                    <th style="width:40px;">#</th>
                    <th>اللاعب</th>
                    <th>النوع</th>
                    <th>الحالة الطبية</th>
                    <th>المجموعات الحالية</th>
                    <th style="width:100px;">إجراء</th>
                </tr>
            </thead>
            <tbody>
                <?php if (empty($players)): ?>
                <tr>
                    <td colspan="6" style="text-align:center;padding:30px;color:#6B7280;">لا يوجد لاعبون مطابقون</td>
                </tr>
                <?php else: ?>
                <?php foreach ($players as $i => $p): ?>
                <?php
                    $medColors = ['fit' => '#059669', 'conditional' => '#D97706', 'pending' => '#6B7280', 'expired' => '#DC2626', 'unfit' => '#DC2626'];
                    $medLabels = ['fit' => 'لائق', 'conditional' => 'مشروط', 'pending' => 'معلق', 'expired' => 'منتهي', 'unfit' => 'غير لائق'];
                    $ms = $p['medical_status'] ?? 'pending';
                ?>
                <tr>
                    <td><?= $i + 1 ?></td>
                    <td>
                        <div style="display:flex;align-items:center;gap:10px;">
                            <div style="width:36px;height:36px;border-radius:50%;background:#F3F4F6;display:flex;align-items:center;justify-content:center;overflow:hidden;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: ?>
                                <i data-lucide="user" style="width:18px;height:18px;color:#9CA3AF;"></i>
                                <?php endif; ?>
                            </div>
                            <div>
                                <div style="font-weight:600;font-size:13px;"><?= e($p['full_name_ar']) ?></div>
                                <?php if ($p['phone']): ?>
                                <div style="font-size:11px;color:#6B7280;"><?= e($p['phone']) ?></div>
                                <?php endif; ?>
                            </div>
                        </div>
                    </td>
                    <td>
                        <span style="font-size:11px;padding:2px 8px;border-radius:8px;background:<?= $p['player_type'] === 'member' ? '#ECFDF5' : '#FEF3C7' ?>;color:<?= $p['player_type'] === 'member' ? '#059669' : '#D97706' ?>;">
                            <?= $p['player_type'] === 'member' ? 'عضو' : 'غير عضو' ?>
                        </span>
                    </td>
                    <td>
                        <span style="font-size:11px;padding:2px 8px;border-radius:8px;background:<?= $medColors[$ms] ?? '#6B7280' ?>15;color:<?= $medColors[$ms] ?? '#6B7280' ?>;">
                            <?= $medLabels[$ms] ?? $ms ?>
                        </span>
                    </td>
                    <td style="font-size:12px;color:#6B7280;"><?= e($p['current_groups'] ?? '—') ?></td>
                    <td>
                        <a href="/sa/assignments/<?= (int) $p['id'] ?>?discipline_id=<?= e($filters['discipline_id'] ?? '') ?>" class="btn btn-sm btn-primary" style="font-size:12px;padding:5px 12px;">
                            <i data-lucide="user-plus" style="width:13px;height:13px;vertical-align:middle;margin-left:3px;"></i> تعيين
                        </a>
                    </td>
                </tr>
                <?php endforeach; ?>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>

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