<?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-plus me-2"></i>
                        إضافة مستخدم جديد
                    </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.store')); ?>" method="POST" enctype="multipart/form-data" id="createUserForm">
                        <?php echo csrf_field(); ?>

                        <!-- معلومات التصحيح -->
                        <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>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 Authenticated: <code><?php echo e(Auth::check() ? 'نعم' : 'لا'); ?></code></li>
                                <?php if(Auth::check()): ?>
                                    <li>User Type: <code><?php echo e(Auth::user()->user_type); ?></code></li>
                                    <li>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')); ?>" 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')); ?>" 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')); ?>" 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') == $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')); ?></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">كلمة المرور <span class="text-danger">*</span></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" required
                                           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">تأكيد كلمة المرور <span class="text-danger">*</span></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" required
                                           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') == 'taxi' ? 'selected' : ''); ?>>تاكسي</option>
                                        <option value="restaurant" <?php echo e(old('service_type') == 'restaurant' ? 'selected' : ''); ?>>مطعم</option>
                                        <option value="gas" <?php echo e(old('service_type') == 'gas' ? 'selected' : ''); ?>>غاز</option>
                                        <option value="all" <?php echo e(old('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') == 'active' ? 'selected' : ''); ?>>نشط</option>
                                        <option value="inactive" <?php echo e(old('status') == 'inactive' ? 'selected' : ''); ?>>غير نشط</option>
                                        <option value="suspended" <?php echo e(old('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') == 'passenger' ? 'selected' : ''); ?>>راكب</option>
                                        <option value="driver" <?php echo e(old('user_type') == 'driver' ? 'selected' : ''); ?>>سائق</option>
                                        <option value="admin" <?php echo e(old('user_type') == 'admin' ? 'selected' : ''); ?>>مدير</option>
                                        <option value="restaurant_manager" <?php echo e(old('user_type') == 'restaurant_manager' ? 'selected' : ''); ?>>مدير مطعم</option>
                                        <option value="gas_manager" <?php echo e(old('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>
                                    <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')); ?></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">
                                        <div class="mb-3">
                                            <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')); ?>"
                                                   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 <?php $__errorArgs = ['vehicle_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="vehicle_type" name="vehicle_type">
                                                <option value="">اختر نوع المركبة</option>
                                                <option value="sedan" <?php echo e(old('vehicle_type') == 'sedan' ? 'selected' : ''); ?>>سيارة عادية</option>
                                                <option value="suv" <?php echo e(old('vehicle_type') == 'suv' ? 'selected' : ''); ?>>سيارة رياضية</option>
                                                <option value="van" <?php echo e(old('vehicle_type') == 'van' ? 'selected' : ''); ?>>فان</option>
                                                <option value="motorcycle" <?php echo e(old('vehicle_type') == 'motorcycle' ? 'selected' : ''); ?>>دراجة نارية</option>
                                            </select>
                                            <?php $__errorArgs = ['vehicle_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>

                                    <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')); ?>" 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') == '1' ? 'selected' : ''); ?>>نعم</option>
                                                <option value="0" <?php echo e(old('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');
    
    // إخفاء/إظهار حقل service_type بناءً على نوع المستخدم
    function toggleServiceTypeField() {
        const serviceTypeContainer = document.getElementById('service_type_container');
        const serviceTypeSelect = document.getElementById('service_type');
        const userType = userTypeSelect.value;

        if (userType === 'restaurant_manager' || userType === 'gas_manager') {
            serviceTypeContainer.style.display = 'none';
            // تعيين القيمة المناسبة تلقائياً
            if (userType === 'restaurant_manager') {
                serviceTypeSelect.value = 'restaurant';
            } else if (userType === 'gas_manager') {
                serviceTypeSelect.value = 'gas';
            }
        } else {
            serviceTypeContainer.style.display = 'block';
        }
    }

    // تشغيل عند تغيير نوع المستخدم
    userTypeSelect.addEventListener('change', toggleServiceTypeField);
    
    // تشغيل عند تحميل الصفحة
    toggleServiceTypeField();
    const driverInfo = document.getElementById('driver_info');
    const form = document.getElementById('createUserForm');
    const submitBtn = document.getElementById('submitBtn');

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

    // اختبار CSRF Token
    const csrfToken = document.querySelector('input[name="_token"]');
    console.log('CSRF Token موجود:', !!csrfToken);
    if (csrfToken) {
        console.log('CSRF Token value:', csrfToken.value);
    }

    function toggleDriverInfo() {
        if (userTypeSelect.value === 'driver') {
            driverInfo.style.display = 'block';
        } else {
            driverInfo.style.display = 'none';
        }
    }

    // تحميل المدن عند اختيار المحافظة
    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);
                    });
            }
        });
    }

    // إضافة 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);

            // التحقق من صحة البيانات قبل الإرسال - السماح بحقول فارغة للسائق
            console.log('جاري التحقق من البيانات...');

            // إظهار رسالة تأكيد وتعطيل الزر
            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 : 'غير موجود'
    });
});
</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/create.blade.php ENDPATH**/ ?>