<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>إضافة نشاط رياضي جديد<?php $__template->endSection(); ?>

<?php $__template->section('page_actions'); ?>
<a href="/disciplines" 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="/disciplines" id="disciplineForm">
    <?= 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="file-text" 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="text" name="name_ar" value="<?= e(old('name_ar')) ?>" class="form-input" required placeholder="مثال: كرة القدم">
                </div>
                <div class="form-group">
                    <label class="form-label">الاسم بالإنجليزي</label>
                    <input type="text" name="name_en" value="<?= e(old('name_en')) ?>" class="form-input" id="nameEn" placeholder="e.g. Football" 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>
                    <input type="text" name="code" value="<?= e(old('code')) ?>" class="form-input" id="codeInput" required placeholder="مثال: FOOTBALL" style="direction:ltr;text-align:left;text-transform:uppercase;">
                    <small style="color:#9CA3AF;font-size:11px;">يتم توليده تلقائيا من الاسم الإنجليزي</small>
                </div>
                <div class="form-group">
                    <label class="form-label">الفئة <span style="color:#DC2626;">*</span></label>
                    <select name="category" class="form-select" required>
                        <option value="">-- اختر الفئة --</option>
                        <?php foreach ($categories as $key => $label): ?>
                        <option value="<?= e($key) ?>" <?= old('category') === $key ? 'selected' : '' ?>><?= e($label) ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div class="form-group">
                    <label class="form-label">ترتيب العرض</label>
                    <input type="number" name="sort_order" value="<?= e(old('sort_order', '0')) ?>" class="form-input" min="0" style="direction:ltr;text-align:left;">
                </div>
            </div>
            <div style="display:grid;grid-template-columns:1fr 1fr;gap:20px;margin-top:15px;">
                <div class="form-group">
                    <label class="form-label">الأيقونة</label>
                    <select name="icon" class="form-select" id="iconSelect">
                        <?php
                        $icons = [
                            'activity' => 'Activity (نشاط)',
                            'trophy' => 'Trophy (كأس)',
                            'target' => 'Target (هدف)',
                            'zap' => 'Zap (طاقة)',
                            'flame' => 'Flame (شعلة)',
                            'heart' => 'Heart (قلب)',
                            'star' => 'Star (نجمة)',
                            'award' => 'Award (جائزة)',
                            'shield' => 'Shield (درع)',
                            'swords' => 'Swords (سيوف)',
                            'bike' => 'Bike (دراجة)',
                            'dumbbell' => 'Dumbbell (دمبل)',
                            'waves' => 'Waves (أمواج)',
                            'wind' => 'Wind (رياح)',
                            'mountain' => 'Mountain (جبل)',
                            'flag' => 'Flag (علم)',
                            'timer' => 'Timer (مؤقت)',
                            'gauge' => 'Gauge (مقياس)',
                            'volleyball' => 'Volleyball (كرة طائرة)',
                            'dribbble' => 'Ball (كرة)',
                            'circle-dot' => 'Circle Dot (دائرة)',
                            'move' => 'Move (حركة)',
                            'grab' => 'Grab (قبضة)',
                            'footprints' => 'Footprints (خطوات)',
                        ];
                        $selectedIcon = old('icon', 'activity');
                        foreach ($icons as $iconKey => $iconLabel):
                        ?>
                        <option value="<?= e($iconKey) ?>" <?= $selectedIcon === $iconKey ? 'selected' : '' ?>><?= e($iconLabel) ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div class="form-group" style="display:flex;align-items:end;gap:10px;">
                    <div id="iconPreview" style="width:48px;height:48px;border-radius:10px;background:#F3F4F6;display:flex;align-items:center;justify-content:center;">
                        <i data-lucide="activity" style="width:24px;height:24px;color:#0D7377;" id="iconPreviewIcon"></i>
                    </div>
                    <span style="font-size:12px;color:#9CA3AF;">معاينة الأيقونة</span>
                </div>
            </div>
            <div class="form-group" style="margin-top:15px;">
                <label class="form-label">وصف النشاط</label>
                <textarea name="description_ar" class="form-input" rows="3" placeholder="وصف مختصر للنشاط الرياضي..."><?= e(old('description_ar')) ?></textarea>
            </div>
        </div>
    </div>

    <!-- Additional Settings -->
    <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="settings" style="width:18px;height:18px;color:#D97706;"></i>
            <h3 style="margin:0;color:#D97706;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 style="display:flex;align-items:center;gap:8px;cursor:pointer;padding:12px;border:1px solid #E5E7EB;border-radius:8px;">
                        <input type="checkbox" name="requires_medical_cert" value="1" <?= old('requires_medical_cert') ? 'checked' : '' ?> style="width:18px;height:18px;accent-color:#0D7377;">
                        <div>
                            <div style="font-size:13px;font-weight:600;color:#1A1A2E;">شهادة طبية مطلوبة</div>
                            <div style="font-size:11px;color:#9CA3AF;">يجب تقديم شهادة لياقة طبية</div>
                        </div>
                    </label>
                </div>
                <div class="form-group">
                    <label class="form-label">موافقة ولي الأمر لمن هم أقل من (سنة)</label>
                    <input type="number" name="requires_guardian_consent_under" value="<?= e(old('requires_guardian_consent_under')) ?>" class="form-input" min="0" max="21" placeholder="مثال: 18" style="direction:ltr;text-align:left;">
                </div>
                <div class="form-group">
                    <label class="form-label">الحد الأقصى للاعبين في الحصة</label>
                    <input type="number" name="max_players_per_session" value="<?= e(old('max_players_per_session')) ?>" class="form-input" min="1" placeholder="مثال: 20" style="direction:ltr;text-align:left;">
                </div>
            </div>
        </div>
    </div>

    <!-- Submit Buttons -->
    <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="/disciplines" 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();
    }

    // Auto-generate code from English name
    var nameEnInput = document.getElementById('nameEn');
    var codeInput = document.getElementById('codeInput');
    if (nameEnInput && codeInput) {
        nameEnInput.addEventListener('input', function() {
            if (codeInput.dataset.manuallyEdited !== 'true') {
                codeInput.value = this.value
                    .toUpperCase()
                    .replace(/[^A-Z0-9\s]/g, '')
                    .replace(/\s+/g, '_')
                    .substring(0, 30);
            }
        });
        codeInput.addEventListener('input', function() {
            this.dataset.manuallyEdited = 'true';
        });
    }

    // Icon preview
    var iconSelect = document.getElementById('iconSelect');
    if (iconSelect) {
        iconSelect.addEventListener('change', function() {
            var preview = document.getElementById('iconPreviewIcon');
            if (preview) {
                preview.setAttribute('data-lucide', this.value);
                if (typeof lucide !== 'undefined') {
                    lucide.createIcons();
                }
            }
        });
    }
});


</script>

<?php $__template->endSection(); ?>
