<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>إضافة لعبة ترفيهية<?php $__template->endSection(); ?>

<?php $__template->section('page_actions'); ?>
<a href="/sa/games" 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'); ?>
<div class="card" style="max-width:700px;">
    <div style="padding:15px 20px;border-bottom:1px solid #E5E7EB;">
        <h3 style="margin:0;font-size:15px;color:#0D7377;">بيانات اللعبة</h3>
    </div>
    <div style="padding:20px;">
        <form method="POST" action="/sa/games">
            <?= csrf_field() ?>

            <div style="display:grid;grid-template-columns:1fr 1fr;gap:15px;">
                <div class="form-group">
                    <label class="form-label">اسم اللعبة (عربي) <span style="color:#DC2626;">*</span></label>
                    <input type="text" name="name_ar" class="form-input" required value="<?= e(old('name_ar')) ?>">
                </div>
                <div class="form-group">
                    <label class="form-label">اسم اللعبة (إنجليزي)</label>
                    <input type="text" name="name_en" class="form-input" value="<?= e(old('name_en')) ?>">
                </div>
                <div class="form-group">
                    <label class="form-label">نوع اللعبة</label>
                    <select name="game_type" class="form-input">
                        <option value="free_play">لعب حر</option>
                        <option value="session">جلسة محددة</option>
                        <option value="tournament">بطولة</option>
                    </select>
                </div>
                <div class="form-group">
                    <label class="form-label">المرفق</label>
                    <select name="facility_id" class="form-input">
                        <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="number" name="max_players" class="form-input" value="20" min="1" max="200">
                </div>
                <div class="form-group">
                    <label class="form-label">المدة (دقيقة)</label>
                    <input type="number" name="duration_minutes" class="form-input" value="60" min="15" max="480">
                </div>
                <div class="form-group">
                    <label class="form-label">نوع التسعير <span style="color:#DC2626;">*</span></label>
                    <select name="pricing_type" id="pricing_type" class="form-input">
                        <option value="per_game" <?= old('pricing_type') === 'per_game' ? 'selected' : '' ?>>لكل لعبة</option>
                        <option value="per_hour" <?= old('pricing_type') === 'per_hour' ? 'selected' : '' ?>>بالساعة</option>
                    </select>
                </div>
                <div class="form-group">
                    <label class="form-label" id="fee_member_label">رسوم العضو (ج.م)</label>
                    <input type="number" name="fee_member" class="form-input" value="<?= e(old('fee_member', '0')) ?>" min="0" step="0.01">
                </div>
                <div class="form-group">
                    <label class="form-label" id="fee_nonmember_label">رسوم غير العضو (ج.م)</label>
                    <input type="number" name="fee_nonmember" class="form-input" value="<?= e(old('fee_nonmember', '0')) ?>" min="0" step="0.01">
                </div>
            </div>

            <div class="form-group">
                <label class="form-label">الوصف</label>
                <textarea name="description" class="form-input" rows="3" placeholder="وصف اختياري للعبة..."><?= e(old('description')) ?></textarea>
            </div>

            <div style="padding-top:15px;border-top:1px solid #F3F4F6;">
                <button type="submit" class="btn btn-primary">
                    <i data-lucide="save" style="width:15px;height:15px;vertical-align:middle;margin-left:4px;"></i> حفظ
                </button>
            </div>
        </form>
    </div>
</div>

<script>
document.addEventListener('DOMContentLoaded', function() {
    if (typeof lucide !== 'undefined') lucide.createIcons();

    var pricingType = document.getElementById('pricing_type');
    var feeMemberLabel = document.getElementById('fee_member_label');
    var feeNonmemberLabel = document.getElementById('fee_nonmember_label');

    function updateFeeLabels() {
        var suffix = pricingType.value === 'per_hour' ? ' / ساعة' : ' / لعبة';
        feeMemberLabel.textContent = 'رسوم العضو (ج.م)' + suffix;
        feeNonmemberLabel.textContent = 'رسوم غير العضو (ج.م)' + suffix;
    }
    pricingType.addEventListener('change', updateFeeLabels);
    updateFeeLabels();
});
</script>
<?php $__template->endSection(); ?>
