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

<?php $__template->section('page_actions'); ?>
<a href="/academies/<?= (int) $academy->id ?>" class="btn btn-outline"><i data-lucide="eye" style="width:15px;height:15px;vertical-align:middle;margin-left:4px;"></i> عرض</a>
<a href="/academies" 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
$ageMin = $config['age_min'] ?? '';
$ageMax = $config['age_max'] ?? '';
$capacity = $config['capacity'] ?? '';
?>

<form method="POST" action="/academies/<?= (int) $academy->id ?>" id="academyForm">
    <?= 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') ?: $academy->name_ar) ?>" class="form-input" required>
                </div>
                <div class="form-group">
                    <label class="form-label">الاسم بالإنجليزي</label>
                    <input type="text" name="name_en" value="<?= e(old('name_en') ?: ($academy->name_en ?? '')) ?>" class="form-input" id="nameEn" 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">كود الأكاديمية</label>
                    <input type="text" name="code" value="<?= e(old('code') ?: $academy->code) ?>" class="form-input" id="codeInput" style="direction:ltr;text-align:left;text-transform:uppercase;">
                </div>
                <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 $disc): ?>
                        <option value="<?= (int) $disc['id'] ?>" <?= (old('discipline_id') ?: $academy->discipline_id) == $disc['id'] ? 'selected' : '' ?>><?= e($disc['name_ar']) ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div class="form-group">
                    <label class="form-label">نوع الأكاديمية <span style="color:#DC2626;">*</span></label>
                    <select name="academy_type" class="form-select" required>
                        <option value="">-- اختر النوع --</option>
                        <?php foreach ($academyTypes as $key => $label): ?>
                        <option value="<?= e($key) ?>" <?= (old('academy_type') ?: ($academy->academy_type ?? '')) === $key ? 'selected' : '' ?>><?= e($label) ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
            </div>
            <div style="display:grid;grid-template-columns:3fr 1fr;gap:20px;margin-top:15px;">
                <div class="form-group">
                    <label class="form-label">وصف الأكاديمية</label>
                    <textarea name="description_ar" class="form-input" rows="3"><?= e(old('description_ar') ?: ($academy->description_ar ?? '')) ?></textarea>
                </div>
                <div class="form-group">
                    <label class="form-label">ترتيب العرض</label>
                    <input type="number" name="sort_order" value="<?= e(old('sort_order') ?: (string)($academy->sort_order ?? 0)) ?>" class="form-input" min="0" style="direction:ltr;text-align:left;">
                </div>
            </div>
        </div>
    </div>

    <!-- Config Card -->
    <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 class="form-label">الحد الأدنى للسن</label>
                    <input type="number" name="age_min" value="<?= e(old('age_min') ?: (string) $ageMin) ?>" class="form-input" min="0" max="99" placeholder="مثال: 5" style="direction:ltr;text-align:left;">
                </div>
                <div class="form-group">
                    <label class="form-label">الحد الأقصى للسن</label>
                    <input type="number" name="age_max" value="<?= e(old('age_max') ?: (string) $ageMax) ?>" class="form-input" min="0" max="99" placeholder="مثال: 18" style="direction:ltr;text-align:left;">
                </div>
                <div class="form-group">
                    <label class="form-label">السعة الاستيعابية</label>
                    <input type="number" name="capacity" value="<?= e(old('capacity') ?: (string) $capacity) ?>" class="form-input" min="1" placeholder="مثال: 100" 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="/academies/<?= (int) $academy->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(); ?>
