<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>البرنامج: <?= e($program['name_ar']) ?><?php $__template->endSection(); ?>

<?php $__template->section('page_actions'); ?>
<a href="/sa/programs/<?= (int) $program['id'] ?>/edit" class="btn btn-primary" style="margin-left:8px;"><i data-lucide="edit-3" style="width:15px;height:15px;vertical-align:middle;margin-left:4px;"></i> تعديل</a>
<a href="/sa/programs" class="btn btn-outline"><i data-lucide="arrow-right" style="width:15px;height:15px;vertical-align:middle;margin-left:4px;"></i> العودة للقائمة</a>
<?php $__template->endSection(); ?>

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

<?php
$genderLabels = ['mixed' => 'مختلط', 'male' => 'ذكور فقط', 'female' => 'إناث فقط'];
?>

<!-- Program Details -->
<div class="card" style="margin-bottom:20px;">
    <div style="padding:15px 20px;border-bottom:1px solid #E5E7EB;">
        <h3 style="margin:0;color:#0D7377;font-size:15px;">بيانات البرنامج</h3>
    </div>
    <div style="padding:20px;">
        <div style="display:grid;grid-template-columns:1fr 1fr 1fr;gap:20px;">
            <div>
                <div style="font-size:12px;color:#6B7280;margin-bottom:4px;">الكود</div>
                <div style="font-weight:600;"><code style="background:#F3F4F6;padding:2px 8px;border-radius:4px;"><?= e($program['code']) ?></code></div>
            </div>
            <div>
                <div style="font-size:12px;color:#6B7280;margin-bottom:4px;">اللعبة / النشاط</div>
                <div style="font-weight:600;"><?= e($program['discipline_name'] ?? '—') ?></div>
            </div>
            <div>
                <div style="font-size:12px;color:#6B7280;margin-bottom:4px;">الأكاديمية</div>
                <div style="font-weight:600;"><?= e($program['academy_name'] ?? '—') ?></div>
            </div>
            <div>
                <div style="font-size:12px;color:#6B7280;margin-bottom:4px;">نوع البرنامج</div>
                <div style="font-weight:600;"><?= e($programTypes[$program['program_type'] ?? ''] ?? '—') ?></div>
            </div>
            <div>
                <div style="font-size:12px;color:#6B7280;margin-bottom:4px;">الفئة العمرية</div>
                <div style="font-weight:600;">
                    <?php if ($program['age_from'] !== null || $program['age_to'] !== null): ?>
                    <?= $program['age_from'] ?? '?' ?> - <?= $program['age_to'] ?? '?' ?> سنة
                    <?php else: ?>
                    —
                    <?php endif; ?>
                </div>
            </div>
            <div>
                <div style="font-size:12px;color:#6B7280;margin-bottom:4px;">الجنس</div>
                <div style="font-weight:600;"><?= e($genderLabels[$program['gender_restriction'] ?? 'mixed'] ?? '—') ?></div>
            </div>
            <div>
                <div style="font-size:12px;color:#6B7280;margin-bottom:4px;">المستوى</div>
                <div style="font-weight:600;"><?= e($skillLevels[$program['skill_level'] ?? ''] ?? '—') ?></div>
            </div>
            <div>
                <div style="font-size:12px;color:#6B7280;margin-bottom:4px;">مدة الحصة</div>
                <div style="font-weight:600;"><?= $program['session_duration_minutes'] ? $program['session_duration_minutes'] . ' دقيقة' : '—' ?></div>
            </div>
            <div>
                <div style="font-size:12px;color:#6B7280;margin-bottom:4px;">الحصص أسبوعياً</div>
                <div style="font-weight:600;"><?= $program['sessions_per_week'] ?? '—' ?></div>
            </div>
            <div>
                <div style="font-size:12px;color:#6B7280;margin-bottom:4px;">رسوم الأعضاء (شهري)</div>
                <div style="font-weight:600;color:#059669;"><?= money((float) ($program['monthly_fee_member'] ?? 0)) ?></div>
            </div>
            <div>
                <div style="font-size:12px;color:#6B7280;margin-bottom:4px;">رسوم غير الأعضاء (شهري)</div>
                <div style="font-weight:600;color:#D97706;"><?= money((float) ($program['monthly_fee_nonmember'] ?? 0)) ?></div>
            </div>
            <div>
                <div style="font-size:12px;color:#6B7280;margin-bottom:4px;">السعة (أدنى / أقصى)</div>
                <div style="font-weight:600;"><?= (int) ($program['min_capacity'] ?? 1) ?> / <?= (int) ($program['max_capacity'] ?? 20) ?></div>
            </div>
        </div>
        <?php if (!empty($program['description_ar'])): ?>
        <div style="margin-top:15px;padding-top:15px;border-top:1px solid #F3F4F6;">
            <div style="font-size:12px;color:#6B7280;margin-bottom:4px;">الوصف</div>
            <div><?= e($program['description_ar']) ?></div>
        </div>
        <?php endif; ?>
    </div>
</div>

<!-- Groups Table -->
<div class="card">
    <div style="padding:15px 20px;border-bottom:1px solid #E5E7EB;display:flex;align-items:center;justify-content:space-between;">
        <h3 style="margin:0;color:#0D7377;font-size:15px;">المجموعات (<?= count($groups) ?>)</h3>
        <a href="/sa/groups/create?program_id=<?= (int) $program['id'] ?>" class="btn btn-sm btn-primary">
            <i data-lucide="plus" style="width:14px;height:14px;vertical-align:middle;margin-left:4px;"></i> إضافة مجموعة
        </a>
    </div>
    <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($groups)): ?>
                <?php
                $statusOptions = \App\Modules\SportsActivity\Models\Group::getStatusOptions();
                ?>
                <?php foreach ($groups as $g): ?>
                <tr>
                    <td><code style="font-size:11px;background:#F3F4F6;padding:2px 6px;border-radius:4px;"><?= e($g['code']) ?></code></td>
                    <td><a href="/sa/groups/<?= (int) $g['id'] ?>" style="text-decoration:none;color:#1A1A2E;font-weight:600;"><?= e($g['name_ar']) ?></a></td>
                    <td><?= e($g['coach_name'] ?? '—') ?></td>
                    <td>
                        <span style="font-weight:600;color:<?= (int)$g['current_count'] >= (int)$g['max_capacity'] ? '#DC2626' : '#059669' ?>;">
                            <?= (int) $g['current_count'] ?>
                        </span>
                        / <?= (int) $g['max_capacity'] ?>
                    </td>
                    <td><?= money((float) ($program['monthly_fee_member'] ?? 0)) ?></td>
                    <td>
                        <?php
                        $statusColors = ['active' => '#059669', 'paused' => '#D97706', 'completed' => '#6B7280', 'cancelled' => '#DC2626'];
                        $statusBgs = ['active' => '#ECFDF5', 'paused' => '#FEF3C7', 'completed' => '#F3F4F6', 'cancelled' => '#FEE2E2'];
                        $st = $g['status'] ?? 'active';
                        ?>
                        <span style="background:<?= $statusBgs[$st] ?? '#F3F4F6' ?>;color:<?= $statusColors[$st] ?? '#6B7280' ?>;padding:3px 10px;border-radius:10px;font-size:12px;font-weight:600;">
                            <?= e($statusOptions[$st] ?? $st) ?>
                        </span>
                    </td>
                    <td>
                        <a href="/sa/groups/<?= (int) $g['id'] ?>" class="btn btn-sm btn-outline" style="font-size:12px;padding:4px 10px;">
                            <i data-lucide="eye" style="width:13px;height:13px;vertical-align:middle;"></i> عرض
                        </a>
                    </td>
                </tr>
                <?php endforeach; ?>
                <?php else: ?>
                <tr>
                    <td colspan="7" style="text-align:center;padding:30px;color:#6B7280;">لا توجد مجموعات لهذا البرنامج بعد</td>
                </tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>

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