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

<?php $__env->startSection('content'); ?>
<div class="container-fluid">
    <?php if(session('success')): ?>
        <div class="alert alert-success alert-dismissible fade show" role="alert">
            <i class="fas fa-check-circle me-2"></i>
            <?php echo e(session('success')); ?>

            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        </div>
    <?php endif; ?>

    <?php if(session('error')): ?>
        <div class="alert alert-danger alert-dismissible fade show" role="alert">
            <i class="fas fa-exclamation-triangle me-2"></i>
            <?php echo e(session('error')); ?>

            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        </div>
    <?php endif; ?>

    <?php if($errors->any()): ?>
        <div class="alert alert-danger alert-dismissible fade show" role="alert">
            <i class="fas fa-exclamation-triangle me-2"></i>
            <strong>يوجد أخطاء في النموذج:</strong>
            <ul class="mb-0 mt-2">
                <?php $__currentLoopData = $errors->all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $error): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <li><?php echo e($error); ?></li>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </ul>
            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        </div>
    <?php endif; ?>

    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-header">
                    <h4 class="card-title">
                        <i class="fas fa-user-edit me-2"></i>
                        تعديل المستخدم: <?php echo e($user->name); ?>

                    </h4>
                    <a href="<?php echo e(route('admin.users')); ?>" class="btn btn-secondary">
                        <i class="fas fa-arrow-right me-1"></i> رجوع
                    </a>
                </div>
                <div class="card-body">
                    <form action="<?php echo e(route('admin.users.update', $user->id)); ?>" method="POST" enctype="multipart/form-data" id="editUserForm">
                        <?php echo csrf_field(); ?>
                        <?php echo method_field('PUT'); ?>

                        <!-- معلومات التصحيح -->
                        <div class="alert alert-info mb-4">
                            <h6><i class="fas fa-info-circle me-2"></i>معلومات التصحيح:</h6>
                            <ul class="mb-0">
                                <li>CSRF Token: <code><?php echo e(csrf_token()); ?></code></li>
                                <li>Method Field: <code><?php echo e(old('_method', 'PUT')); ?></code></li>
                                <li>Route: <code><?php echo e(request()->route()->getName()); ?></code></li>
                                <li>Method: <code><?php echo e(request()->method()); ?></code></li>
                                <li>URL: <code><?php echo e(request()->url()); ?></code></li>
                                <li>User ID: <code><?php echo e($user->id); ?></code></li>
                                <li>User Authenticated: <code><?php echo e(Auth::check() ? 'نعم' : 'لا'); ?></code></li>
                                <?php if(Auth::check()): ?>
                                    <li>Current User Type: <code><?php echo e(Auth::user()->user_type); ?></code></li>
                                    <li>Current User Status: <code><?php echo e(Auth::user()->status); ?></code></li>
                                <?php endif; ?>
                            </ul>
                        </div>

                        <div class="row">
                            <!-- المعلومات الأساسية -->
                            <div class="col-md-6">
                                <h5 class="mb-3 text-primary">
                                    <i class="fas fa-user me-2"></i>
                                    المعلومات الأساسية
                                </h5>

                                <div class="mb-3">
                                    <label for="name" class="form-label">الاسم الكامل <span class="text-danger">*</span></label>
                                    <input type="text" class="form-control <?php $__errorArgs = ['name'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                                           id="name" name="name" value="<?php echo e(old('name', $user->name)); ?>" required
                                           placeholder="أدخل الاسم الكامل">
                                    <?php $__errorArgs = ['name'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                        <div class="invalid-feedback"><?php echo e($message); ?></div>
                                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                </div>

                                <div class="mb-3">
                                    <label for="email" class="form-label">البريد الإلكتروني <span class="text-danger">*</span></label>
                                    <input type="email" class="form-control <?php $__errorArgs = ['email'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                                           id="email" name="email" value="<?php echo e(old('email', $user->email)); ?>" required
                                           placeholder="أدخل البريد الإلكتروني">
                                    <?php $__errorArgs = ['email'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                        <div class="invalid-feedback"><?php echo e($message); ?></div>
                                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                </div>

                                <div class="mb-3">
                                    <label for="phone" class="form-label">رقم الهاتف <span class="text-danger">*</span></label>
                                    <input type="tel" class="form-control <?php $__errorArgs = ['phone'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                                           id="phone" name="phone" value="<?php echo e(old('phone', $user->phone)); ?>" required
                                           placeholder="أدخل رقم الهاتف">
                                    <?php $__errorArgs = ['phone'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                        <div class="invalid-feedback"><?php echo e($message); ?></div>
                                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                </div>

                                <!-- المحافظة والمدينة -->
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="mb-3">
                                            <label for="governorate_id" class="form-label">المحافظة</label>
                                            <select class="form-control <?php $__errorArgs = ['governorate_id'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>" 
                                                    id="governorate_id" name="governorate_id">
                                                <option value="">اختر المحافظة</option>
                                                <?php $__currentLoopData = \App\Models\Governorate::active()->orderBy('name_ar')->get(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $governorate): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <option value="<?php echo e($governorate->id); ?>" 
                                                            <?php echo e(old('governorate_id', $user->governorate_id) == $governorate->id ? 'selected' : ''); ?>>
                                                        <?php echo e($governorate->name_ar); ?>

                                                    </option>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </select>
                                            <?php $__errorArgs = ['governorate_id'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                                <div class="invalid-feedback"><?php echo e($message); ?></div>
                                            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="mb-3">
                                            <label for="city_id" class="form-label">المدينة</label>
                                            <select class="form-control <?php $__errorArgs = ['city_id'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>" 
                                                    id="city_id" name="city_id">
                                                <option value="">اختر المدينة</option>
                                            </select>
                                            <?php $__errorArgs = ['city_id'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                                <div class="invalid-feedback"><?php echo e($message); ?></div>
                                            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                        </div>
                                    </div>
                                </div>

                                <div class="mb-3">
                                    <label for="address" class="form-label">العنوان التفصيلي</label>
                                    <textarea class="form-control <?php $__errorArgs = ['address'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                                              id="address" name="address" rows="2"
                                              placeholder="أدخل العنوان التفصيلي"><?php echo e(old('address', $user->address)); ?></textarea>
                                    <?php $__errorArgs = ['address'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                        <div class="invalid-feedback"><?php echo e($message); ?></div>
                                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                </div>

                                <div class="mb-3">
                                    <label for="password" class="form-label">كلمة المرور الجديدة (اتركها فارغة إذا لم ترد تغييرها)</label>
                                    <input type="password" class="form-control <?php $__errorArgs = ['password'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                                           id="password" name="password"
                                           placeholder="أدخل كلمة المرور الجديدة (8 أحرف على الأقل)">
                                    <?php $__errorArgs = ['password'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                        <div class="invalid-feedback"><?php echo e($message); ?></div>
                                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                </div>

                                <div class="mb-3">
                                    <label for="password_confirmation" class="form-label">تأكيد كلمة المرور الجديدة</label>
                                    <input type="password" class="form-control <?php $__errorArgs = ['password_confirmation'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                                           id="password_confirmation" name="password_confirmation"
                                           placeholder="أعد إدخال كلمة المرور الجديدة">
                                    <?php $__errorArgs = ['password_confirmation'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                        <div class="invalid-feedback"><?php echo e($message); ?></div>
                                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                </div>
                            </div>

                            <!-- معلومات إضافية -->
                            <div class="col-md-6">
                                <h5 class="mb-3 text-primary">
                                    <i class="fas fa-cog me-2"></i>
                                    معلومات إضافية
                                </h5>

                                <div class="mb-3">
                                    <label for="service_type" class="form-label">نوع الخدمة</label>
                                    <select class="form-select <?php $__errorArgs = ['service_type'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                                            id="service_type" name="service_type">
                                        <option value="">اختر نوع الخدمة</option>
                                        <option value="taxi" <?php echo e(old('service_type', $user->service_type) == 'taxi' ? 'selected' : ''); ?>>تاكسي</option>
                                        <option value="food_delivery" <?php echo e(old('service_type', $user->service_type) == 'food_delivery' ? 'selected' : ''); ?>>توصيل طعام</option>
                                        <option value="gas_delivery" <?php echo e(old('service_type', $user->service_type) == 'gas_delivery' ? 'selected' : ''); ?>>توصيل غاز</option>
                                        <option value="all" <?php echo e(old('service_type', $user->service_type) == 'all' ? 'selected' : ''); ?>>جميع الخدمات</option>
                                    </select>
                                    <?php $__errorArgs = ['service_type'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                        <div class="invalid-feedback"><?php echo e($message); ?></div>
                                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                </div>

                                <div class="mb-3">
                                    <label for="status" class="form-label">الحالة</label>
                                    <select class="form-select <?php $__errorArgs = ['status'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                                            id="status" name="status">
                                        <option value="active" <?php echo e(old('status', $user->status) == 'active' ? 'selected' : ''); ?>>نشط</option>
                                        <option value="inactive" <?php echo e(old('status', $user->status) == 'inactive' ? 'selected' : ''); ?>>غير نشط</option>
                                        <option value="suspended" <?php echo e(old('status', $user->status) == 'suspended' ? 'selected' : ''); ?>>معلق</option>
                                    </select>
                                    <?php $__errorArgs = ['status'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                        <div class="invalid-feedback"><?php echo e($message); ?></div>
                                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                </div>

                                <div class="mb-3">
                                    <label for="user_type" class="form-label">نوع المستخدم</label>
                                    <select class="form-select <?php $__errorArgs = ['user_type'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                                            id="user_type" name="user_type">
                                        <option value="passenger" <?php echo e(old('user_type', $user->user_type) == 'passenger' ? 'selected' : ''); ?>>راكب</option>
                                        <option value="driver" <?php echo e(old('user_type', $user->user_type) == 'driver' ? 'selected' : ''); ?>>سائق</option>
                                        <option value="admin" <?php echo e(old('user_type', $user->user_type) == 'admin' ? 'selected' : ''); ?>>مدير</option>
                                        <option value="restaurant_manager" <?php echo e(old('user_type', $user->user_type) == 'restaurant_manager' ? 'selected' : ''); ?>>مدير مطعم</option>
                                        <option value="gas_manager" <?php echo e(old('user_type', $user->user_type) == 'gas_manager' ? 'selected' : ''); ?>>مدير مكتب غاز</option>
                                    </select>
                                    <?php $__errorArgs = ['user_type'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                        <div class="invalid-feedback"><?php echo e($message); ?></div>
                                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                </div>

                                <div class="mb-3">
                                    <label for="profile_image" class="form-label">صورة الملف الشخصي</label>
                                    <?php if($user->profile_image): ?>
                                        <div class="mb-2">
                                            <img src="<?php echo e(asset('storage/' . $user->profile_image)); ?>"
                                                 alt="صورة المستخدم" class="img-thumbnail" style="max-width: 100px;">
                                            <small class="d-block text-muted">الصورة الحالية</small>
                                        </div>
                                    <?php endif; ?>
                                    <input type="file" class="form-control <?php $__errorArgs = ['profile_image'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                                           id="profile_image" name="profile_image" accept="image/*">
                                    <small class="form-text text-muted">الحد الأقصى: 2MB، الأنواع المدعومة: JPG, PNG, GIF</small>
                                    <?php $__errorArgs = ['profile_image'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                        <div class="invalid-feedback"><?php echo e($message); ?></div>
                                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                </div>

                                <div class="mb-3">
                                    <label for="notes" class="form-label">ملاحظات</label>
                                    <textarea class="form-control <?php $__errorArgs = ['notes'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                                              id="notes" name="notes" rows="3"
                                              placeholder="أدخل أي ملاحظات إضافية"><?php echo e(old('notes', $user->notes)); ?></textarea>
                                    <?php $__errorArgs = ['notes'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                        <div class="invalid-feedback"><?php echo e($message); ?></div>
                                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                </div>
                            </div>
                        </div>

                        <!-- معلومات السائق (تظهر فقط عند اختيار دور السائق) -->
                        <div id="driver_info" class="row mt-4" style="display: none;">
                            <div class="col-12">
                                <h5 class="mb-3 text-warning">
                                    <i class="fas fa-car me-2"></i>
                                    معلومات السائق
                                </h5>
                                <div class="row">
                                    <div class="col-md-6">
                                        <label for="license_number" class="form-label">رقم رخصة القيادة</label>
                                        <input type="text" class="form-control <?php $__errorArgs = ['license_number'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                                               id="license_number" name="license_number"
                                               value="<?php echo e(old('license_number', $user->driver->license_number ?? '')); ?>"
                                               placeholder="أدخل رقم رخصة القيادة (اختياري - سيتم تعيينه لاحقاً)">
                                        <?php $__errorArgs = ['license_number'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                            <div class="invalid-feedback"><?php echo e($message); ?></div>
                                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                        <small class="form-text text-muted">يمكن للسائق تعبئة هذا الحقل لاحقاً عند إكمال معلومات سيارته</small>
                                    </div>

                                        <div class="mb-3">
                                            <label for="vehicle_type" class="form-label">نوع المركبة</label>
                                            <select class="form-select" id="vehicle_type" name="vehicle_type">
                                                <option value="">اختر نوع المركبة</option>
                                                <option value="sedan" <?php echo e(old('vehicle_type', $user->driver->vehicle_type ?? '') == 'sedan' ? 'selected' : ''); ?>>سيارة عادية</option>
                                                <option value="suv" <?php echo e(old('vehicle_type', $user->driver->vehicle_type ?? '') == 'suv' ? 'selected' : ''); ?>>سيارة رياضية</option>
                                                <option value="van" <?php echo e(old('vehicle_type', $user->driver->vehicle_type ?? '') == 'van' ? 'selected' : ''); ?>>فان</option>
                                                <option value="motorcycle" <?php echo e(old('vehicle_type', $user->driver->vehicle_type ?? '') == 'motorcycle' ? 'selected' : ''); ?>>دراجة نارية</option>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="col-md-6">
                                        <div class="mb-3">
                                            <label for="experience_years" class="form-label">سنوات الخبرة</label>
                                            <input type="number" class="form-control" id="experience_years" name="experience_years"
                                                   value="<?php echo e(old('experience_years', $user->driver->experience_years ?? '')); ?>" min="0" max="50"
                                                   placeholder="عدد سنوات الخبرة">
                                        </div>

                                        <div class="mb-3">
                                            <label for="is_available" class="form-label">متاح للعمل</label>
                                            <select class="form-select" id="is_available" name="is_available">
                                                <option value="1" <?php echo e(old('is_available', $user->driver->is_available ?? '') == '1' ? 'selected' : ''); ?>>نعم</option>
                                                <option value="0" <?php echo e(old('is_available', $user->driver->is_available ?? '') == '0' ? 'selected' : ''); ?>>لا</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="row mt-4">
                            <div class="col-12">
                                <button type="submit" class="btn btn-primary" id="submitBtn">
                                    <i class="fas fa-save me-2"></i> تحديث المستخدم
                                </button>
                                <a href="<?php echo e(route('admin.users')); ?>" class="btn btn-secondary">
                                    <i class="fas fa-times me-2"></i> إلغاء
                                </a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
<script>
document.addEventListener('DOMContentLoaded', function() {
    console.log('تم تحميل صفحة تعديل المستخدم');

    const userTypeSelect = document.getElementById('user_type');
    const driverInfo = document.getElementById('driver_info');
    const form = document.getElementById('editUserForm');
    const submitBtn = document.getElementById('submitBtn');

    // اختبار وجود العناصر
    console.log('العناصر الموجودة:', {
        userTypeSelect: !!userTypeSelect,
        driverInfo: !!driverInfo,
        form: !!form,
        submitBtn: !!submitBtn
    });

    // اختبار CSRF Token و Method Field
    const csrfToken = document.querySelector('input[name="_token"]');
    const methodField = document.querySelector('input[name="_method"]');

    console.log('CSRF Token موجود:', !!csrfToken);
    if (csrfToken) {
        console.log('CSRF Token value:', csrfToken.value);
    }

    console.log('Method Field موجود:', !!methodField);
    if (methodField) {
        console.log('Method Field value:', methodField.value);
    }

    function toggleDriverInfo() {
        const licenseNumberField = document.getElementById('license_number');

        if (userTypeSelect.value === 'driver') {
            driverInfo.style.display = 'block';
            if (licenseNumberField) {
                licenseNumberField.required = true;
            }
        } else {
            driverInfo.style.display = 'none';
            if (licenseNumberField) {
                licenseNumberField.required = false;
            }
        }
    }

    // تحميل المدن عند اختيار المحافظة
    const governorateSelect = document.getElementById('governorate_id');
    const citySelect = document.getElementById('city_id');

    if (governorateSelect && citySelect) {
        // تحميل المدن عند تغيير المحافظة
        governorateSelect.addEventListener('change', function() {
            const governorateId = this.value;
            console.log('تم اختيار المحافظة:', governorateId);
            
            // مسح المدن الحالية
            citySelect.innerHTML = '<option value="">اختر المدينة</option>';
            
            if (governorateId) {
                console.log('جاري تحميل المدن للمحافظة:', governorateId);
                // تحميل المدن عبر AJAX
                fetch(`/admin/cities/by-governorate?governorate_id=${governorateId}`)
                    .then(response => {
                        console.log('استجابة الخادم:', response.status);
                        return response.json();
                    })
                    .then(cities => {
                        console.log('المدن المستلمة:', cities);
                        cities.forEach(city => {
                            const option = document.createElement('option');
                            option.value = city.id;
                            option.textContent = city.name_ar;
                            citySelect.appendChild(option);
                        });
                    })
                    .catch(error => {
                        console.error('خطأ في تحميل المدن:', error);
                    });
            }
        });

        // تحميل المدن عند تحميل الصفحة إذا كانت المحافظة محددة
        const currentGovernorateId = governorateSelect.value;
        if (currentGovernorateId) {
            fetch(`/admin/cities/by-governorate?governorate_id=${currentGovernorateId}`)
                .then(response => response.json())
                .then(cities => {
                    cities.forEach(city => {
                        const option = document.createElement('option');
                        option.value = city.id;
                        option.textContent = city.name_ar;
                        if (city.id == <?php echo e($user->city_id ?? 'null'); ?>) {
                            option.selected = true;
                        }
                        citySelect.appendChild(option);
                    });
                })
                .catch(error => {
                    console.error('خطأ في تحميل المدن:', error);
                });
        }
    }

    // إضافة event listener للنموذج
    if (form) {
        form.addEventListener('submit', function(e) {
            console.log('تم إرسال النموذج');

            // جمع بيانات النموذج
            const formData = new FormData(form);
            const data = {};
            for (let [key, value] of formData.entries()) {
                data[key] = value;
            }

            console.log('بيانات النموذج:', data);

            // التحقق من صحة البيانات قبل الإرسال
            if (userTypeSelect.value === 'driver') {
                const licenseNumber = document.getElementById('license_number');
                if (licenseNumber && !licenseNumber.value.trim()) {
                    e.preventDefault();
                    alert('يرجى إدخال رقم رخصة القيادة للسائق');
                    return false;
                }
            }

            // إظهار رسالة تأكيد وتعطيل الزر
            if (submitBtn) {
                submitBtn.disabled = true;
                submitBtn.innerHTML = '<i class="fas fa-spinner fa-spin me-2"></i> جاري التحديث...';
            }

            // إرسال النموذج
            console.log('إرسال النموذج...');
            return true;
        });
    } else {
        console.error('النموذج غير موجود!');
    }

    // إضافة event listener لتغيير نوع المستخدم
    if (userTypeSelect) {
        userTypeSelect.addEventListener('change', function() {
            console.log('تم تغيير نوع المستخدم إلى:', this.value);
            toggleDriverInfo();
        });
    }

    // تشغيل عند تحميل الصفحة
    toggleDriverInfo();

    // اختبار إضافي للتحقق من صحة النموذج
    console.log('اختبار صحة النموذج:', {
        formAction: form ? form.action : 'غير موجود',
        formMethod: form ? form.method : 'غير موجود',
        formEnctype: form ? form.enctype : 'غير موجود'
    });

    // اختبار البيانات الحالية للمستخدم
    console.log('بيانات المستخدم الحالية:', {
        id: <?php echo e($user->id); ?>,
        name: '<?php echo e($user->name); ?>',
        email: '<?php echo e($user->email); ?>',
        user_type: '<?php echo e($user->user_type); ?>',
        status: '<?php echo e($user->status); ?>',
        hasDriver: <?php echo e($user->driver ? 'true' : 'false'); ?>

    });
});
</script>
<?php $__env->stopPush(); ?>

<?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/users/edit.blade.php ENDPATH**/ ?>