<?php
use App\Modules\Reservations\Models\Reservation;
$__template->layout('Layout.main');
?>
<?php $__template->section('title'); ?>حجز جديد<?php $__template->endSection(); ?>

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

    <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="calendar-plus" style="width:18px;height:18px;color:#0D7377;"></i>
            <h3 style="margin:0;color:#0D7377;font-size:15px;">بيانات الحجز</h3>
        </div>
        <div style="padding:20px;display:grid;grid-template-columns:1fr 1fr;gap:15px;">

            <!-- Facility -->
            <div>
                <label class="form-label">المرفق <span style="color:#DC2626;">*</span></label>
                <select name="facility_id" class="form-input" 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>

            <!-- Reservation Date -->
            <div>
                <label class="form-label">تاريخ الحجز <span style="color:#DC2626;">*</span></label>
                <input type="date" name="reservation_date" value="<?= e(old('reservation_date')) ?>" class="form-input" required style="direction:ltr;text-align:left;">
            </div>

            <!-- Start Time -->
            <div>
                <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>

            <!-- End Time -->
            <div>
                <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>

            <!-- Booker Type -->
            <div>
                <label class="form-label">نوع الحاجز <span style="color:#DC2626;">*</span></label>
                <select name="booker_type" class="form-input" required>
                    <option value="">-- اختر النوع --</option>
                    <?php foreach ($bookerTypes as $code => $label): ?>
                    <option value="<?= e($code) ?>" <?= old('booker_type') === $code ? 'selected' : '' ?>><?= e($label) ?></option>
                    <?php endforeach; ?>
                </select>
            </div>

            <!-- Booker Name -->
            <div>
                <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 placeholder="الاسم بالكامل">
            </div>

            <!-- Booker Phone -->
            <div>
                <label class="form-label">هاتف الحاجز</label>
                <input type="text" name="booker_phone" value="<?= e(old('booker_phone')) ?>" class="form-input" placeholder="رقم الهاتف" style="direction:ltr;text-align:left;">
            </div>

            <!-- Player ID -->
            <div>
                <label class="form-label">رقم اللاعب</label>
                <input type="number" name="player_id" value="<?= e(old('player_id')) ?>" class="form-input" placeholder="اختياري" style="direction:ltr;text-align:left;">
            </div>

            <!-- Member ID -->
            <div>
                <label class="form-label">رقم العضوية</label>
                <input type="number" name="member_id" value="<?= e(old('member_id')) ?>" class="form-input" placeholder="اختياري" style="direction:ltr;text-align:left;">
            </div>

            <!-- Notes -->
            <div style="grid-column:1/-1;">
                <label class="form-label">ملاحظات</label>
                <textarea name="notes" class="form-input" rows="3" placeholder="ملاحظات إضافية..."><?= e(old('notes')) ?></textarea>
            </div>
        </div>
    </div>

    <div style="display:flex;gap:10px;">
        <button type="submit" class="btn btn-primary">
            <i data-lucide="check" style="width:16px;height:16px;vertical-align:middle;margin-left:4px;"></i> إنشاء الحجز
        </button>
        <a href="/reservations" class="btn btn-outline">إلغاء</a>
    </div>
</form>

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