<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>إضافة مرفق جديد<?php $__template->endSection(); ?>

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

    <!-- Basic Information -->
    <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="file-text" 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>
                    <input type="text" name="code" value="<?= e(old('code')) ?>" class="form-input" placeholder="يتم توليده تلقائياً" style="direction:ltr;text-align:left;text-transform:uppercase;">
                    <small style="color:#9CA3AF;font-size:11px;">اختياري — يتم توليده تلقائياً</small>
                </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="مثال: ملعب 1">
                </div>
                <div class="form-group">
                    <label class="form-label">الاسم بالإنجليزي</label>
                    <input type="text" name="name_en" value="<?= e(old('name_en')) ?>" class="form-input" placeholder="e.g. Pitch 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>
                    <select name="facility_type" class="form-select" required>
                        <option value="">-- اختر النوع --</option>
                        <?php foreach ($types as $key => $label): ?>
                        <option value="<?= e($key) ?>" <?= old('facility_type') === $key ? 'selected' : '' ?>><?= e($label) ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div class="form-group">
                    <label class="form-label">الموقع <span style="color:#DC2626;">*</span></label>
                    <select name="location" class="form-select" required>
                        <option value="">-- اختر الموقع --</option>
                        <?php foreach ($locations as $key => $label): ?>
                        <option value="<?= e($key) ?>" <?= old('location') === $key ? 'selected' : '' ?>><?= e($label) ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div class="form-group">
                    <label class="form-label">السعة</label>
                    <input type="number" name="capacity" value="<?= e(old('capacity')) ?>" class="form-input" min="0" placeholder="مثال: 22" style="direction:ltr;text-align:left;">
                </div>
            </div>
            <div style="display:grid;grid-template-columns:1fr 1fr;gap:20px;margin-top:15px;">
                <div class="form-group">
                    <label class="form-label">النشاط المرتبط</label>
                    <select name="linked_discipline_id" class="form-select">
                        <option value="">-- بدون ربط --</option>
                        <?php foreach ($disciplines as $disc): ?>
                        <option value="<?= (int) $disc['id'] ?>" <?= old('linked_discipline_id') == $disc['id'] ? 'selected' : '' ?>><?= e($disc['name_ar'] ?? '') ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div class="form-group">
                    <label class="form-label">الوصف</label>
                    <textarea name="description" class="form-input" rows="2" placeholder="وصف مختصر للمرفق..."><?= e(old('description')) ?></textarea>
                </div>
            </div>
        </div>
    </div>

    <!-- Rates Card -->
    <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="banknote" style="width:18px;height:18px;color:#059669;"></i>
            <h3 style="margin:0;color:#059669;font-size:15px;">الأسعار بالساعة</h3>
        </div>
        <div style="padding:20px;">
            <div style="display:grid;grid-template-columns:1fr 1fr;gap:20px;">
                <div class="form-group">
                    <label class="form-label">
                        <i data-lucide="sun" style="width:14px;height:14px;vertical-align:middle;color:#D97706;"></i>
                        سعر الأعضاء (صباحي)
                    </label>
                    <input type="number" name="hourly_rate_member" value="<?= e(old('hourly_rate_member')) ?>" class="form-input" min="0" step="0.01" placeholder="0.00" style="direction:ltr;text-align:left;">
                </div>
                <div class="form-group">
                    <label class="form-label">
                        <i data-lucide="sun" style="width:14px;height:14px;vertical-align:middle;color:#D97706;"></i>
                        سعر غير الأعضاء (صباحي)
                    </label>
                    <input type="number" name="hourly_rate_nonmember" value="<?= e(old('hourly_rate_nonmember')) ?>" class="form-input" min="0" step="0.01" placeholder="0.00" style="direction:ltr;text-align:left;">
                </div>
            </div>
            <div style="display:grid;grid-template-columns:1fr 1fr;gap:20px;margin-top:15px;">
                <div class="form-group">
                    <label class="form-label">
                        <i data-lucide="moon" style="width:14px;height:14px;vertical-align:middle;color:#7C3AED;"></i>
                        سعر الأعضاء (مسائي)
                    </label>
                    <input type="number" name="hourly_rate_member_pm" value="<?= e(old('hourly_rate_member_pm')) ?>" class="form-input" min="0" step="0.01" placeholder="0.00" style="direction:ltr;text-align:left;">
                </div>
                <div class="form-group">
                    <label class="form-label">
                        <i data-lucide="moon" style="width:14px;height:14px;vertical-align:middle;color:#7C3AED;"></i>
                        سعر غير الأعضاء (مسائي)
                    </label>
                    <input type="number" name="hourly_rate_nonmember_pm" value="<?= e(old('hourly_rate_nonmember_pm')) ?>" class="form-input" min="0" step="0.01" placeholder="0.00" style="direction:ltr;text-align:left;">
                </div>
            </div>
        </div>
    </div>

    <!-- Submit Buttons -->
    <div style="display:flex;gap:10px;justify-content:flex-start;">
        <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="/facilities" 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(); ?>
