<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>تعديل حمام السباحة: <?= e($pool->name_ar) ?><?php $__template->endSection(); ?>

<?php $__template->section('page_actions'); ?>
<a href="/pool/<?= (int) $pool->id ?>/grid" class="btn btn-outline"><i data-lucide="grid-3x3" style="width:15px;height:15px;vertical-align:middle;margin-left:4px;"></i> الشبكة</a>
<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/<?= (int) $pool->id ?>">
    <?= 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">المرفق</label>
                    <select name="facility_id" class="form-select" disabled>
                        <?php foreach ($facilities as $f): ?>
                        <option value="<?= (int) $f['id'] ?>" <?= (int) $pool->facility_id === (int) $f['id'] ? 'selected' : '' ?>><?= e($f['name_ar']) ?></option>
                        <?php endforeach; ?>
                    </select>
                    <div style="font-size:11px;color:#9CA3AF;margin-top:4px;">لا يمكن تغيير المرفق بعد الإنشاء</div>
                </div>
                <div class="form-group">
                    <label class="form-label">الاسم بالعربي <span style="color:#DC2626;">*</span></label>
                    <input type="text" name="name_ar" value="<?= e($pool->name_ar) ?>" class="form-input" required>
                </div>
                <div class="form-group">
                    <label class="form-label">الاسم بالإنجليزي</label>
                    <input type="text" name="name_en" value="<?= e($pool->name_en ?? '') ?>" class="form-input" style="direction:ltr;text-align:left;">
                </div>
            </div>
        </div>
    </div>

    <!-- Dimensions (read-only info + editable parts) -->
    <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:repeat(4, 1fr);gap:20px;">
                <div class="form-group">
                    <label class="form-label">الطول (متر)</label>
                    <input type="text" value="<?= e((string) $pool->length_meters) ?>" class="form-input" disabled style="direction:ltr;text-align:left;">
                </div>
                <div class="form-group">
                    <label class="form-label">العرض (متر)</label>
                    <input type="text" value="<?= e((string) $pool->width_meters) ?>" class="form-input" disabled style="direction:ltr;text-align:left;">
                </div>
                <div class="form-group">
                    <label class="form-label">العمق الضحل (متر)</label>
                    <input type="number" name="depth_shallow" value="<?= e((string) ($pool->depth_shallow ?? '')) ?>" 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((string) ($pool->depth_deep ?? '')) ?>" 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">عدد الحارات</label>
                    <input type="text" value="<?= (int) $pool->total_lanes_lengthwise ?>" class="form-input" disabled style="direction:ltr;text-align:left;">
                </div>
                <div class="form-group">
                    <label class="form-label">الحد الأقصى الإجمالي</label>
                    <input type="number" name="max_total_swimmers" value="<?= (int) $pool->max_total_swimmers ?>" 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="<?= (int) $pool->max_per_lane ?>" class="form-input" min="1" style="direction:ltr;text-align:left;">
                </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="<?= (int) ($safety['lap_swimming'] ?? 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="<?= (int) ($safety['lessons'] ?? 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="<?= (int) ($safety['free_swim'] ?? 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="<?= (int) ($safety['academy_session'] ?? 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="<?= (int) ($safety['competition'] ?? 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="<?= e($hours['start'] ?? '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="<?= e($hours['end'] ?? '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" <?= (int) ($hours['slot_minutes'] ?? 60) === 30 ? 'selected' : '' ?>>30 دقيقة</option>
                        <option value="60" <?= (int) ($hours['slot_minutes'] ?? 60) === 60 ? 'selected' : '' ?>>60 دقيقة (ساعة)</option>
                        <option value="90" <?= (int) ($hours['slot_minutes'] ?? 60) === 90 ? 'selected' : '' ?>>90 دقيقة</option>
                        <option value="120" <?= (int) ($hours['slot_minutes'] ?? 60) === 120 ? 'selected' : '' ?>>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="save" style="width:16px;height:16px;vertical-align:middle;margin-left:4px;"></i> حفظ التعديلات
        </button>
        <a href="/pool/<?= (int) $pool->id ?>/grid" 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(); ?>
