<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>إضافة حمام سباحة<?php $__template->endSection(); ?>

<?php $__template->section('page_actions'); ?>
<a href="/pool" 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="/pool/config" id="poolConfigForm">
    <?= csrf_field() ?>

    <!-- Basic Info -->
    <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="waves" 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>
                    <select name="facility_id" class="form-select" required>
                        <option value="">-- اختر مرفق حمام سباحة --</option>
                        <?php foreach ($facilities as $f): ?>
                        <option value="<?= (int) $f['id'] ?>" <?= old('facility_id') == $f['id'] ? 'selected' : '' ?>><?= e($f['name_ar']) ?></option>
                        <?php endforeach; ?>
                    </select>
                </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') ?? '') ?>" 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" style="direction:ltr;text-align:left;" placeholder="Olympic Pool">
                </div>
            </div>
        </div>
    </div>

    <!-- Dimensions -->
    <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="ruler" style="width:18px;height:18px;color:#2563EB;"></i>
            <h3 style="margin:0;color:#2563EB;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">الطول (متر) <span style="color:#DC2626;">*</span></label>
                    <input type="number" name="length_meters" value="<?= e(old('length_meters') ?? '50') ?>" class="form-input" min="5" max="100" step="0.5" required 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="width_meters" value="<?= e(old('width_meters') ?? '25') ?>" class="form-input" min="3" max="50" step="0.5" required style="direction:ltr;text-align:left;">
                </div>
                <div class="form-group">
                    <label class="form-label">العمق الضحل (متر)</label>
                    <input type="number" name="depth_shallow" value="<?= e(old('depth_shallow') ?? '1.2') ?>" class="form-input" min="0.5" max="5" step="0.1" style="direction:ltr;text-align:left;">
                </div>
                <div class="form-group">
                    <label class="form-label">العمق العميق (متر)</label>
                    <input type="number" name="depth_deep" value="<?= e(old('depth_deep') ?? '2.0') ?>" class="form-input" min="0.5" max="10" step="0.1" 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="number" name="total_lanes_lengthwise" value="<?= e(old('total_lanes_lengthwise') ?? '6') ?>" class="form-input" min="1" max="12" required style="direction:ltr;text-align:left;" id="laneCount">
                </div>
                <div class="form-group">
                    <label class="form-label">الحد الأقصى الإجمالي</label>
                    <input type="number" name="max_total_swimmers" value="<?= e(old('max_total_swimmers') ?? '50') ?>" class="form-input" min="1" style="direction:ltr;text-align:left;">
                </div>
                <div class="form-group">
                    <label class="form-label">حد أقصى لكل حارة</label>
                    <input type="number" name="max_per_lane" value="<?= e(old('max_per_lane') ?? '8') ?>" class="form-input" min="1" style="direction:ltr;text-align:left;">
                </div>
            </div>

            <!-- Visual Preview -->
            <div style="margin-top:20px;padding:15px;background:#F0FDFA;border-radius:8px;border:1px solid #CCFBF1;">
                <div style="font-size:12px;color:#059669;margin-bottom:8px;font-weight:600;">معاينة تقريبية:</div>
                <div id="lanePreview" style="display:flex;gap:3px;height:50px;"></div>
            </div>
        </div>
    </div>

    <!-- Safety Ratios -->
    <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="shield" style="width:18px;height:18px;color:#DC2626;"></i>
            <h3 style="margin:0;color:#DC2626;font-size:15px;">حدود الأمان (أقصى عدد سبّاحين/حارة)</h3>
        </div>
        <div style="padding:20px;">
            <div style="display:grid;grid-template-columns:repeat(5, 1fr);gap:15px;">
                <div class="form-group">
                    <label class="form-label" style="font-size:12px;">سباحة حرة</label>
                    <input type="number" name="safety_lap" value="6" class="form-input" min="1" max="20" style="direction:ltr;text-align:left;">
                </div>
                <div class="form-group">
                    <label class="form-label" style="font-size:12px;">دروس</label>
                    <input type="number" name="safety_lessons" value="4" class="form-input" min="1" max="20" style="direction:ltr;text-align:left;">
                </div>
                <div class="form-group">
                    <label class="form-label" style="font-size:12px;">ترفيهي</label>
                    <input type="number" name="safety_free" value="8" class="form-input" min="1" max="20" style="direction:ltr;text-align:left;">
                </div>
                <div class="form-group">
                    <label class="form-label" style="font-size:12px;">أكاديمية</label>
                    <input type="number" name="safety_academy" value="5" class="form-input" min="1" max="20" style="direction:ltr;text-align:left;">
                </div>
                <div class="form-group">
                    <label class="form-label" style="font-size:12px;">مسابقة</label>
                    <input type="number" name="safety_competition" value="4" class="form-input" min="1" max="20" style="direction:ltr;text-align:left;">
                </div>
            </div>
        </div>
    </div>

    <!-- Operating Hours -->
    <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:#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="time" name="op_start" value="06:00" class="form-input" style="direction:ltr;text-align:left;">
                </div>
                <div class="form-group">
                    <label class="form-label">وقت الإغلاق</label>
                    <input type="time" name="op_end" value="22:00" class="form-input" style="direction:ltr;text-align:left;">
                </div>
                <div class="form-group">
                    <label class="form-label">مدة الفترة (دقيقة)</label>
                    <select name="slot_minutes" class="form-select">
                        <option value="30">30 دقيقة</option>
                        <option value="60" selected>60 دقيقة (ساعة)</option>
                        <option value="90">90 دقيقة</option>
                        <option value="120">120 دقيقة (ساعتين)</option>
                    </select>
                </div>
            </div>
        </div>
    </div>

    <!-- Submit -->
    <div style="display:flex;gap:10px;">
        <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="/pool" 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();
    updateLanePreview();
    document.getElementById('laneCount').addEventListener('input', updateLanePreview);
});

function updateLanePreview() {
    var count = parseInt(document.getElementById('laneCount').value) || 6;
    var container = document.getElementById('lanePreview');
    container.innerHTML = '';
    for (var i = 1; i <= count; i++) {
        var div = document.createElement('div');
        div.style.cssText = 'flex:1;background:#CCFBF1;border:1px dashed #0D737740;border-radius:4px;display:flex;align-items:center;justify-content:center;font-size:11px;color:#0D7377;';
        div.textContent = i;
        container.appendChild(div);
    }
}
</script>

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