<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>تعديل: <?= e($discipline->name_ar) ?><?php $__template->endSection(); ?>

<?php $__template->section('page_actions'); ?>
<a href="/sa/disciplines/<?= (int) $discipline->id ?>" class="btn btn-outline"><i data-lucide="eye" style="width:15px;height:15px;vertical-align:middle;margin-left:4px;"></i> عرض</a>
<a href="/sa/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="/sa/disciplines/<?= (int) $discipline->id ?>" 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="code" value="<?= e(old('code') ?: $discipline->code) ?>" class="form-input" required 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') ?: $discipline->name_ar) ?>" class="form-input" required>
                </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">الاسم بالإنجليزي</label>
                    <input type="text" name="name_en" value="<?= e(old('name_en') ?: ($discipline->name_en ?? '')) ?>" class="form-input" style="direction:ltr;text-align:left;">
                </div>
                <div class="form-group">
                    <label class="form-label">التصنيف</label>
                    <select name="category" class="form-select">
                        <option value="">-- اختر التصنيف --</option>
                        <?php foreach ($categories as $key => $label): ?>
                        <option value="<?= e($key) ?>" <?= (old('category') ?: ($discipline->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') ?: (string)($discipline->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') ?: ($discipline->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="<?= e($selectedIcon) ?>" 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"><?= e(old('description_ar') ?: ($discipline->description_ar ?? '')) ?></textarea>
            </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="/sa/disciplines/<?= (int) $discipline->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();
    }

    // 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(); ?>
