<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>حجز ملعب لمباراة خاصة<?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>

<div class="card" style="padding:25px;max-width:700px;">
    <form method="POST" action="/private-matches">
        <?= csrf_field() ?>

        <div style="display:grid;grid-template-columns:1fr 1fr;gap:15px;">
            <div class="form-group" style="grid-column:span 2;">
                <label class="form-label">الملعب / المرفق</label>
                <select name="facility_id" class="form-input" required>
                    <option value="">— اختر الملعب —</option>
                    <?php foreach ($facilities as $f): ?>
                    <option value="<?= (int) $f['id'] ?>"><?= e($f['name_ar']) ?></option>
                    <?php endforeach; ?>
                </select>
            </div>

            <div class="form-group">
                <label class="form-label">تاريخ المباراة</label>
                <input type="date" name="booking_date" class="form-input" value="<?= old('booking_date') ?>" required min="<?= date('Y-m-d') ?>">
            </div>

            <div class="form-group">
                <label class="form-label">نوع المباراة</label>
                <select name="match_type" class="form-input">
                    <?php foreach ($matchTypes as $key => $label): ?>
                    <option value="<?= $key ?>"><?= e($label) ?></option>
                    <?php endforeach; ?>
                </select>
            </div>

            <div class="form-group">
                <label class="form-label">وقت البدء</label>
                <input type="time" name="start_time" class="form-input" value="<?= old('start_time') ?>" required>
            </div>

            <div class="form-group">
                <label class="form-label">وقت الانتهاء</label>
                <input type="time" name="end_time" class="form-input" value="<?= old('end_time') ?>" required>
            </div>
        </div>

        <hr style="margin:20px 0;border-color:#E5E7EB;">
        <h5 style="margin-bottom:15px;">بيانات الحاجز</h5>

        <div style="display:grid;grid-template-columns:1fr 1fr;gap:15px;">
            <div class="form-group">
                <label class="form-label">رقم العضوية (إن وجد)</label>
                <input type="number" name="member_id" class="form-input" placeholder="اتركه فارغاً للضيوف">
            </div>
            <div class="form-group">
                <label class="form-label">الاسم</label>
                <input type="text" name="booked_by_name" class="form-input" value="<?= old('booked_by_name') ?>" required>
            </div>
            <div class="form-group">
                <label class="form-label">الهاتف</label>
                <input type="tel" name="booked_by_phone" class="form-input" value="<?= old('booked_by_phone') ?>" style="direction:ltr;text-align:right;">
            </div>
            <div class="form-group">
                <label class="form-label">عدد اللاعبين</label>
                <input type="number" name="players_count" class="form-input" value="10" min="2" max="30">
            </div>
        </div>

        <hr style="margin:20px 0;border-color:#E5E7EB;">
        <h5 style="margin-bottom:15px;">الفرق (اختياري)</h5>

        <div style="display:grid;grid-template-columns:1fr 1fr;gap:15px;">
            <div class="form-group">
                <label class="form-label">اسم الفريق الأول</label>
                <input type="text" name="team_a_name" class="form-input" placeholder="مثال: النسور">
            </div>
            <div class="form-group">
                <label class="form-label">اسم الفريق الثاني</label>
                <input type="text" name="team_b_name" class="form-input" placeholder="مثال: الصقور">
            </div>
        </div>

        <hr style="margin:20px 0;border-color:#E5E7EB;">
        <h5 style="margin-bottom:15px;">التكاليف</h5>

        <div style="display:grid;grid-template-columns:1fr 1fr 1fr;gap:15px;">
            <div class="form-group">
                <label class="form-label">تكلفة الملعب</label>
                <input type="number" name="facility_cost" class="form-input" step="0.01" value="0" min="0">
            </div>
            <div class="form-group">
                <label class="form-label">حكم</label>
                <label style="display:flex;align-items:center;gap:8px;margin-top:8px;">
                    <input type="checkbox" name="has_referee" value="1" onchange="document.getElementById('refCost').style.display = this.checked ? 'block' : 'none';">
                    <span style="font-size:13px;">مع حكم</span>
                </label>
                <div id="refCost" style="display:none;margin-top:8px;">
                    <input type="number" name="referee_cost" class="form-input" step="0.01" value="50" min="0" placeholder="تكلفة الحكم">
                </div>
            </div>
            <div class="form-group">
                <label class="form-label">مقدم مدفوع</label>
                <input type="number" name="deposit_paid" class="form-input" step="0.01" value="0" min="0">
            </div>
        </div>

        <div class="form-group">
            <label class="form-label">ملاحظات</label>
            <textarea name="notes" class="form-input" rows="2" placeholder="أي ملاحظات إضافية..."><?= old('notes') ?></textarea>
        </div>

        <div style="display:flex;gap:10px;margin-top:20px;">
            <button type="submit" class="btn btn-primary">حجز الملعب</button>
            <a href="/private-matches" class="btn btn-outline">إلغاء</a>
        </div>
    </form>
</div>
<?php $__template->endSection(); ?>
