<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>إضافة منشأة جديدة<?php $__template->endSection(); ?>
<?php $__template->section('page_actions'); ?>
<a href="/sa/facilities" class="btn btn-outline">رجوع للقائمة</a>
<?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>

<div class="card" style="max-width:700px;padding:25px;">
    <h3 style="margin:0 0 20px;color:#1F2937;">إضافة منشأة رياضية</h3>

    <form method="POST" action="/sa/facilities">
        <?= csrf_field() ?>

        <div style="display:grid;grid-template-columns:1fr 1fr;gap:15px;margin-bottom:15px;">
            <div>
                <label class="form-label">الكود <span style="color:#DC2626;">*</span></label>
                <input type="text" name="code" value="<?= e(old('code', '')) ?>" class="form-input" required placeholder="مثال: FAC-001">
            </div>
            <div>
                <label class="form-label">نوع المنشأة <span style="color:#DC2626;">*</span></label>
                <select name="facility_type" class="form-select" required>
                    <option value="">اختر النوع</option>
                    <?php foreach ($typeOptions as $key => $label): ?>
                    <option value="<?= e($key) ?>" <?= old('facility_type', '') === $key ? 'selected' : '' ?>><?= e($label) ?></option>
                    <?php endforeach; ?>
                </select>
            </div>
        </div>

        <div style="display:grid;grid-template-columns:1fr 1fr;gap:15px;margin-bottom:15px;">
            <div>
                <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>
            </div>
            <div>
                <label class="form-label">الاسم بالإنجليزية</label>
                <input type="text" name="name_en" value="<?= e(old('name_en', '')) ?>" class="form-input" dir="ltr">
            </div>
        </div>

        <div style="margin-bottom:15px;">
            <label class="form-label">اللعبة / النشاط</label>
            <select name="discipline_id" class="form-select">
                <option value="">بدون تحديد</option>
                <?php foreach ($disciplines as $disc): ?>
                <option value="<?= (int) $disc->id ?>" <?= old('discipline_id', '') == $disc->id ? 'selected' : '' ?>><?= e($disc->name_ar) ?></option>
                <?php endforeach; ?>
            </select>
        </div>

        <div style="margin-bottom:15px;">
            <label class="form-label">وصف الموقع</label>
            <input type="text" name="location_description" value="<?= e(old('location_description', '')) ?>" class="form-input" placeholder="مثال: الدور الأول - جناح B">
        </div>

        <div style="background:#F9FAFB;border:1px solid #E5E7EB;border-radius:8px;padding:15px;margin-bottom:20px;">
            <h4 style="margin:0 0 12px;color:#374151;font-size:14px;">ساعات التشغيل</h4>
            <div style="display:grid;grid-template-columns:1fr 1fr 1fr;gap:15px;">
                <div>
                    <label class="form-label">وقت البدء <span style="color:#DC2626;">*</span></label>
                    <input type="time" name="operating_start" value="<?= e(old('operating_start', '06:00')) ?>" class="form-input" required>
                </div>
                <div>
                    <label class="form-label">وقت الانتهاء <span style="color:#DC2626;">*</span></label>
                    <input type="time" name="operating_end" value="<?= e(old('operating_end', '22:00')) ?>" class="form-input" required>
                </div>
                <div>
                    <label class="form-label">مدة الفترة (دقيقة)</label>
                    <input type="number" name="slot_minutes" value="<?= e(old('slot_minutes', '60')) ?>" class="form-input" min="15" max="240" step="15">
                </div>
            </div>
        </div>

        <div style="display:flex;gap:10px;">
            <button type="submit" class="btn btn-primary">حفظ المنشأة</button>
            <a href="/sa/facilities" class="btn btn-outline">إلغاء</a>
        </div>
    </form>
</div>

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