
<?php
    use Illuminate\Support\Facades\Storage;
?>

<?php $__env->startSection('title', 'تعديل العرض'); ?>

<?php $__env->startSection('content'); ?>
<div class="container-fluid px-0">
    <!-- Header -->
    <div class="row mb-4">
        <div class="col-12">
            <div class="d-flex justify-content-between align-items-center">
                <h1 class="h3 mb-0" style="color: var(--text-light);">
                    <i class="fas fa-edit" style="color: var(--primary-yellow);"></i>
                    تعديل العرض
                </h1>
                <a href="<?php echo e(route('admin.offers-ads.index', ['type' => 'offers'])); ?>" class="btn btn-outline-primary">
                    <i class="fas fa-arrow-right"></i> العودة
                </a>
            </div>
        </div>
    </div>

    <!-- نموذج تعديل العرض -->
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-body">
                    <form action="<?php echo e(route('admin.offers-ads.offers.update', $offer->id)); ?>" method="POST" enctype="multipart/form-data">
                        <?php echo csrf_field(); ?>
                        <?php echo method_field('PUT'); ?>

                        <div class="row g-3">
                            <!-- العنوان -->
                            <div class="col-md-6">
                                <label class="form-label" style="color: var(--text-light);">العنوان (إنجليزي) <span class="text-danger">*</span></label>
                                <input type="text" name="title" class="form-control" value="<?php echo e(old('title', $offer->title)); ?>" required>
                            </div>

                            <div class="col-md-6">
                                <label class="form-label" style="color: var(--text-light);">العنوان (عربي)</label>
                                <input type="text" name="title_ar" class="form-control" value="<?php echo e(old('title_ar', $offer->title_ar)); ?>">
                            </div>

                            <!-- الوصف -->
                            <div class="col-md-6">
                                <label class="form-label" style="color: var(--text-light);">الوصف (إنجليزي)</label>
                                <textarea name="description" class="form-control" rows="3"><?php echo e(old('description', $offer->description)); ?></textarea>
                            </div>

                            <div class="col-md-6">
                                <label class="form-label" style="color: var(--text-light);">الوصف (عربي)</label>
                                <textarea name="description_ar" class="form-control" rows="3"><?php echo e(old('description_ar', $offer->description_ar)); ?></textarea>
                            </div>

                            <!-- الصورة -->
                            <div class="col-md-12">
                                <label class="form-label" style="color: var(--text-light);">صورة العرض</label>
                                <?php if($offer->image): ?>
                                    <div class="mb-2">
                                        <img src="<?php echo e(asset('storage/' . $offer->image)); ?>" alt="<?php echo e($offer->title); ?>" style="max-width: 200px; max-height: 200px; border-radius: 8px;">
                                    </div>
                                <?php endif; ?>
                                <input type="file" name="image" class="form-control" accept="image/*">
                                <small class="text-muted" style="color: rgba(245, 245, 245, 0.7);">اتركه فارغاً للاحتفاظ بالصورة الحالية</small>
                            </div>

                            <!-- نوع العرض -->
                            <div class="col-md-4">
                                <label class="form-label" style="color: var(--text-light);">نوع العرض <span class="text-danger">*</span></label>
                                <select name="offer_type" class="form-control" required>
                                    <option value="general" <?php echo e(old('offer_type', $offer->offer_type) == 'general' ? 'selected' : ''); ?>>عام</option>
                                    <option value="food" <?php echo e(old('offer_type', $offer->offer_type) == 'food' ? 'selected' : ''); ?>>طعام</option>
                                    <option value="gas" <?php echo e(old('offer_type', $offer->offer_type) == 'gas' ? 'selected' : ''); ?>>غاز</option>
                                    <option value="taxi" <?php echo e(old('offer_type', $offer->offer_type) == 'taxi' ? 'selected' : ''); ?>>تاكسي</option>
                                </select>
                            </div>

                            <!-- نوع الرابط -->
                            <div class="col-md-4">
                                <label class="form-label" style="color: var(--text-light);">نوع الرابط <span class="text-danger">*</span></label>
                                <select name="link_type" id="link_type" class="form-control" required onchange="updateLinkFields()">
                                    <option value="none" <?php echo e(old('link_type', $offer->link_type) == 'none' ? 'selected' : ''); ?>>لا يوجد رابط</option>
                                    <option value="restaurant" <?php echo e(old('link_type', $offer->link_type) == 'restaurant' ? 'selected' : ''); ?>>مطعم</option>
                                    <option value="gas_office" <?php echo e(old('link_type', $offer->link_type) == 'gas_office' ? 'selected' : ''); ?>>مكتب غاز</option>
                                    <option value="external" <?php echo e(old('link_type', $offer->link_type) == 'external' ? 'selected' : ''); ?>>رابط خارجي</option>
                                </select>
                            </div>

                            <!-- رابط المطعم -->
                            <div class="col-md-4" id="restaurant_link" style="display: <?php echo e(old('link_type', $offer->link_type) == 'restaurant' ? 'block' : 'none'); ?>;">
                                <label class="form-label" style="color: var(--text-light);">اختر المطعم</label>
                                <select name="link_id" class="form-control">
                                    <option value="">اختر المطعم</option>
                                    <?php $__currentLoopData = $restaurants; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $restaurant): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($restaurant->id); ?>" <?php echo e(old('link_id', $offer->link_id) == $restaurant->id ? 'selected' : ''); ?>>
                                            <?php echo e($restaurant->name); ?>

                                        </option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                            </div>

                            <!-- رابط مكتب الغاز -->
                            <div class="col-md-4" id="gas_office_link" style="display: <?php echo e(old('link_type', $offer->link_type) == 'gas_office' ? 'block' : 'none'); ?>;">
                                <label class="form-label" style="color: var(--text-light);">اختر مكتب الغاز</label>
                                <select name="link_id" class="form-control">
                                    <option value="">اختر مكتب الغاز</option>
                                    <?php $__currentLoopData = $gasOffices; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $office): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($office->id); ?>" <?php echo e(old('link_id', $offer->link_id) == $office->id ? 'selected' : ''); ?>>
                                            <?php echo e($office->name); ?>

                                        </option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                            </div>

                            <!-- رابط خارجي -->
                            <div class="col-md-4" id="external_link" style="display: <?php echo e(old('link_type', $offer->link_type) == 'external' ? 'block' : 'none'); ?>;">
                                <label class="form-label" style="color: var(--text-light);">الرابط الخارجي</label>
                                <input type="url" name="external_link" class="form-control" value="<?php echo e(old('external_link', $offer->external_link)); ?>" placeholder="https://example.com">
                            </div>

                            <!-- الخصم -->
                            <div class="col-md-6">
                                <label class="form-label" style="color: var(--text-light);">نسبة الخصم (%)</label>
                                <input type="number" name="discount_percentage" class="form-control" value="<?php echo e(old('discount_percentage', $offer->discount_percentage)); ?>" min="0" max="100" step="0.01">
                            </div>

                            <div class="col-md-6">
                                <label class="form-label" style="color: var(--text-light);">مبلغ الخصم (دينار)</label>
                                <input type="number" name="discount_amount" class="form-control" value="<?php echo e(old('discount_amount', $offer->discount_amount)); ?>" min="0" step="0.01">
                            </div>

                            <!-- التواريخ -->
                            <div class="col-md-4">
                                <label class="form-label" style="color: var(--text-light);">تاريخ البداية <span class="text-danger">*</span></label>
                                <input type="datetime-local" name="start_date" class="form-control" value="<?php echo e(old('start_date', $offer->start_date->format('Y-m-d\TH:i'))); ?>" required>
                            </div>

                            <div class="col-md-4">
                                <label class="form-label" style="color: var(--text-light);">تاريخ النهاية <span class="text-danger">*</span></label>
                                <input type="datetime-local" name="end_date" class="form-control" value="<?php echo e(old('end_date', $offer->end_date->format('Y-m-d\TH:i'))); ?>" required>
                            </div>

                            <div class="col-md-4">
                                <label class="form-label" style="color: var(--text-light);">ترتيب العرض</label>
                                <input type="number" name="display_order" class="form-control" value="<?php echo e(old('display_order', $offer->display_order)); ?>" min="0">
                            </div>

                            <!-- الحالة -->
                            <div class="col-md-12">
                                <div class="form-check">
                                    <input class="form-check-input" type="checkbox" name="is_active" id="is_active" <?php echo e(old('is_active', $offer->is_active) ? 'checked' : ''); ?>>
                                    <label class="form-check-label" for="is_active" style="color: var(--text-light);">
                                        تفعيل العرض
                                    </label>
                                </div>
                            </div>

                            <!-- الأزرار -->
                            <div class="col-12">
                                <button type="submit" class="btn btn-primary">
                                    <i class="fas fa-save"></i> حفظ التعديلات
                                </button>
                                <a href="<?php echo e(route('admin.offers-ads.index', ['type' => 'offers'])); ?>" class="btn btn-outline-primary">
                                    <i class="fas fa-times"></i> إلغاء
                                </a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
function updateLinkFields() {
    const linkType = document.getElementById('link_type').value;
    document.getElementById('restaurant_link').style.display = linkType === 'restaurant' ? 'block' : 'none';
    document.getElementById('gas_office_link').style.display = linkType === 'gas_office' ? 'block' : 'none';
    document.getElementById('external_link').style.display = linkType === 'external' ? 'block' : 'none';
}

// تحديث الحقول عند تحميل الصفحة
window.onload = function() {
    updateLinkFields();
};
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('admin.layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\wamp64\www\taxi_app\resources\views/admin/offers_ads/edit_offer.blade.php ENDPATH**/ ?>