<?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 ?>" 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'); ?>

<form method="POST" action="/sa/programs/<?= (int) $program->id ?>/update">
    <?= csrf_field() ?>

    <!-- Basic Information -->
    <div class="card" style="margin-bottom:20px;">
        <div style="padding:15px 20px;border-bottom:1px solid #E5E7EB;display:flex;align-items:center;gap:8px;">
            <i data-lucide="book-open" style="width:18px;height:18px;color:#0D7377;"></i>
            <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 class="form-group">
                    <label class="form-label">كود البرنامج <span style="color:#DC2626;">*</span></label>
                    <input type="text" name="code" value="<?= e(old('code', $program->code)) ?>" class="form-input" required maxlength="30" style="direction:ltr;text-align:left;text-transform:uppercase;">
                </div>
                <div class="form-group">
                    <label class="form-label">الاسم بالعربي <span style="color:#DC2626;">*</span></label>
                    <input type="text" name="name_ar" value="<?= e(old('name_ar', $program->name_ar)) ?>" class="form-input" required maxlength="300">
                </div>
                <div class="form-group">
                    <label class="form-label">الاسم بالإنجليزي</label>
                    <input type="text" name="name_en" value="<?= e(old('name_en', $program->name_en ?? '')) ?>" class="form-input" maxlength="300" style="direction:ltr;text-align:left;">
                </div>
            </div>
            <div style="display:grid;grid-template-columns:1fr 1fr 1fr;gap:20px;margin-top:15px;">
                <div class="form-group">
                    <label class="form-label">اللعبة / النشاط <span style="color:#DC2626;">*</span></label>
                    <select name="discipline_id" class="form-select" required>
                        <option value="">-- اختر اللعبة --</option>
                        <?php foreach ($disciplines as $d): ?>
                        <option value="<?= (int) $d['id'] ?>" <?= (old('discipline_id', $program->discipline_id)) == $d['id'] ? 'selected' : '' ?>><?= e($d['name_ar']) ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div class="form-group">
                    <label class="form-label">الأكاديمية (اختياري)</label>
                    <select name="academy_id" class="form-select">
                        <option value="">-- بدون أكاديمية --</option>
                        <?php foreach ($academies as $a): ?>
                        <option value="<?= (int) $a['id'] ?>" <?= (old('academy_id', $program->academy_id ?? '')) == $a['id'] ? 'selected' : '' ?>><?= e($a['name_ar']) ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div class="form-group">
                    <label class="form-label">نوع البرنامج <span style="color:#DC2626;">*</span></label>
                    <select name="program_type" class="form-select" required>
                        <option value="">-- اختر النوع --</option>
                        <?php foreach ($programTypes as $key => $label): ?>
                        <option value="<?= e($key) ?>" <?= old('program_type', $program->program_type ?? '') === $key ? 'selected' : '' ?>><?= e($label) ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
            </div>
        </div>
    </div>

    <!-- Age & Level -->
    <div class="card" style="margin-bottom:20px;">
        <div style="padding:15px 20px;border-bottom:1px solid #E5E7EB;display:flex;align-items:center;gap:8px;">
            <i data-lucide="users" style="width:18px;height:18px;color:#0D7377;"></i>
            <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 1fr;gap:20px;">
                <div class="form-group">
                    <label class="form-label">العمر من</label>
                    <input type="number" name="age_from" value="<?= e(old('age_from', $program->age_from ?? '')) ?>" class="form-input" min="0" max="99" step="1" style="direction:ltr;text-align:left;">
                </div>
                <div class="form-group">
                    <label class="form-label">العمر إلى</label>
                    <input type="number" name="age_to" value="<?= e(old('age_to', $program->age_to ?? '')) ?>" class="form-input" min="0" max="99" step="1" style="direction:ltr;text-align:left;">
                </div>
                <div class="form-group">
                    <label class="form-label">الجنس</label>
                    <select name="gender_restriction" class="form-select">
                        <option value="mixed" <?= old('gender_restriction', $program->gender_restriction ?? 'mixed') === 'mixed' ? 'selected' : '' ?>>مختلط</option>
                        <option value="male" <?= old('gender_restriction', $program->gender_restriction ?? '') === 'male' ? 'selected' : '' ?>>ذكور فقط</option>
                        <option value="female" <?= old('gender_restriction', $program->gender_restriction ?? '') === 'female' ? 'selected' : '' ?>>إناث فقط</option>
                    </select>
                </div>
                <div class="form-group">
                    <label class="form-label">المستوى</label>
                    <select name="skill_level" class="form-select">
                        <option value="">-- الكل --</option>
                        <?php foreach ($skillLevels as $key => $label): ?>
                        <option value="<?= e($key) ?>" <?= old('skill_level', $program->skill_level ?? '') === $key ? 'selected' : '' ?>><?= e($label) ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
            </div>
        </div>
    </div>

    <!-- Session Details -->
    <div class="card" style="margin-bottom:20px;">
        <div style="padding:15px 20px;border-bottom:1px solid #E5E7EB;display:flex;align-items:center;gap:8px;">
            <i data-lucide="clock" style="width:18px;height:18px;color:#0D7377;"></i>
            <h3 style="margin:0;color:#0D7377;font-size:15px;">تفاصيل الحصص</h3>
        </div>
        <div style="padding:20px;">
            <div style="display:grid;grid-template-columns:1fr 1fr;gap:20px;">
                <div class="form-group">
                    <label class="form-label">مدة الحصة (دقيقة) <span style="color:#DC2626;">*</span></label>
                    <input type="number" name="session_duration_minutes" value="<?= e(old('session_duration_minutes', $program->session_duration_minutes ?? '')) ?>" class="form-input" required min="1" max="300" step="1" style="direction:ltr;text-align:left;">
                </div>
                <div class="form-group">
                    <label class="form-label">عدد الحصص أسبوعياً <span style="color:#DC2626;">*</span></label>
                    <input type="number" name="sessions_per_week" value="<?= e(old('sessions_per_week', $program->sessions_per_week ?? '')) ?>" class="form-input" required min="1" max="14" step="1" style="direction:ltr;text-align:left;">
                </div>
            </div>
            <div class="form-group" style="margin-top:15px;">
                <label class="form-label">وصف البرنامج</label>
                <textarea name="description_ar" class="form-input" rows="3"><?= e(old('description_ar', $program->description_ar ?? '')) ?></textarea>
            </div>
        </div>
    </div>

    <!-- Submit -->
    <div style="display:flex;gap:10px;justify-content:flex-start;">
        <button type="submit" class="btn btn-primary" style="padding:12px 30px;font-size:15px;">
            <i data-lucide="check" style="width:16px;height:16px;vertical-align:middle;margin-left:4px;"></i> حفظ التعديلات
        </button>
        <a href="/sa/programs/<?= (int) $program->id ?>" class="btn btn-outline" style="padding:12px 30px;font-size:15px;">إلغاء</a>
    </div>
</form>

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