<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>حجز جديد (بالساعة)<?php $__template->endSection(); ?>

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

    <div style="display:grid;grid-template-columns:2fr 1fr;gap:20px;">
        <!-- Left: Booking Form -->
        <div>
            <!-- Facility & Time -->
            <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="map-pin" style="width:18px;height:18px;color:#0D7377;"></i>
                    <h3 style="margin:0;color:#0D7377;font-size:15px;">المرفق والوقت</h3>
                </div>
                <div style="padding:20px;">
                    <div class="form-group">
                        <label class="form-label">الوحدة / الملعب <span style="color:#DC2626;">*</span></label>
                        <select name="facility_unit_id" class="form-select" required id="unitSelect" data-searchable="true" data-placeholder="ابحث عن الوحدة...">
                            <option value="">-- اختر الوحدة --</option>
                            <?php foreach ($facilityUnitsGrouped as $facilityName => $units): ?>
                            <optgroup label="<?= e($facilityName) ?>">
                                <?php foreach ($units as $u): ?>
                                <option value="<?= (int) $u['id'] ?>" <?= old('facility_unit_id') == $u['id'] ? 'selected' : '' ?>><?= e($u['name_ar']) ?> (<?= e($u['code']) ?>)</option>
                                <?php endforeach; ?>
                            </optgroup>
                            <?php endforeach; ?>
                        </select>
                    </div>
                    <div style="display:grid;grid-template-columns:1fr 1fr 1fr;gap:15px;margin-top:15px;">
                        <div class="form-group">
                            <label class="form-label">تاريخ الحجز <span style="color:#DC2626;">*</span></label>
                            <input type="date" name="booking_date" value="<?= e(old('booking_date', date('Y-m-d'))) ?>" class="form-input" required style="direction:ltr;text-align:left;">
                        </div>
                        <div class="form-group">
                            <label class="form-label">وقت البداية <span style="color:#DC2626;">*</span></label>
                            <input type="time" name="start_time" value="<?= e(old('start_time')) ?>" class="form-input" required style="direction:ltr;text-align:left;">
                        </div>
                        <div class="form-group">
                            <label class="form-label">وقت النهاية <span style="color:#DC2626;">*</span></label>
                            <input type="time" name="end_time" value="<?= e(old('end_time')) ?>" class="form-input" required style="direction:ltr;text-align:left;">
                        </div>
                    </div>
                </div>
            </div>

            <!-- Booker 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="user" 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:15px;">
                        <div class="form-group">
                            <label class="form-label">اسم الحاجز <span style="color:#DC2626;">*</span></label>
                            <input type="text" name="booker_name" value="<?= e(old('booker_name')) ?>" class="form-input" required maxlength="300" placeholder="اسم الشخص الحاجز">
                        </div>
                        <div class="form-group">
                            <label class="form-label">نوع الحاجز</label>
                            <select name="booker_type" class="form-select">
                                <option value="guest" <?= old('booker_type', 'guest') === 'guest' ? 'selected' : '' ?>>زائر</option>
                                <option value="member" <?= old('booker_type') === 'member' ? 'selected' : '' ?>>عضو</option>
                                <option value="employee" <?= old('booker_type') === 'employee' ? 'selected' : '' ?>>موظف</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label class="form-label">عدد المشاركين</label>
                            <input type="number" name="participant_count" value="<?= e(old('participant_count', '1')) ?>" class="form-input" required min="1" step="1" style="direction:ltr;text-align:left;">
                        </div>
                    </div>
                    <div class="form-group" style="margin-top:15px;">
                        <label class="form-label">ملاحظات</label>
                        <textarea name="notes" class="form-input" rows="2" placeholder="أي ملاحظات إضافية..."><?= e(old('notes')) ?></textarea>
                    </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="/sa/bookings" class="btn btn-outline" style="padding:12px 30px;font-size:15px;">إلغاء</a>
            </div>
        </div>

        <!-- Right: Price Preview -->
        <div>
            <div class="card" style="position:sticky;top:20px;">
                <div style="padding:15px 20px;border-bottom:1px solid #E5E7EB;display:flex;align-items:center;gap:8px;">
                    <i data-lucide="receipt" style="width:18px;height:18px;color:#0D7377;"></i>
                    <h3 style="margin:0;color:#0D7377;font-size:15px;">معاينة السعر</h3>
                </div>
                <div style="padding:20px;" id="pricePreview">
                    <div style="text-align:center;padding:30px 0;color:#9CA3AF;">
                        <i data-lucide="calculator" style="width:32px;height:32px;display:block;margin:0 auto 10px;color:#D1D5DB;"></i>
                        <div style="font-size:13px;">اختر الوحدة والوقت لمعرفة السعر</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>

<script>
document.addEventListener('DOMContentLoaded', function() {
    if (typeof lucide !== 'undefined') lucide.createIcons();
});
</script>
<?php $__template->endSection(); ?>
