<?php $__env->startSection('content'); ?>
    <div class="container mt-2">
        <div class="card">
            <div class="card-header"><?php echo e(__('تعديل سؤال')); ?></div>

            <div class="card-body">
                <?php if(session('success')): ?>
                    <div class="alert alert-success"><?php echo e(session('success')); ?></div>
                <?php endif; ?>

                <?php if($errors->any()): ?>
                    <div class="alert alert-danger">
                        <ul class="mb-0">
                            <?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>
                    </div>
                <?php endif; ?>

                <form method="POST" action="<?php echo e(route('questions.update', $question->id)); ?>" id="questionForm">
                    <?php echo csrf_field(); ?>
                    <?php echo method_field('PUT'); ?>

                    <div class="mb-3">
                        <label class="form-label"><?php echo e(__('نص السؤال')); ?></label>
                        <textarea class="form-control" rows="3" name="question_text" required><?php echo e(old('question_text', $question->question_text)); ?></textarea>
                    </div>

                    <?php if(\Illuminate\Support\Facades\Schema::hasColumn('questions', 'sort')): ?>
                        <div class="mb-3">
                            <label class="form-label"><?php echo e(__('الترتيب (sort)')); ?></label>
                            <input class="form-control" type="number" name="sort" min="1" step="1"
                                value="<?php echo e(old('sort', $question->sort)); ?>" required>
                            <div class="form-text"><?php echo e(__('يُستخدم لترتيب عرض الأسئلة في الاستبيان.')); ?></div>
                        </div>
                    <?php endif; ?>

                    <div class="mb-3">
                        <label class="form-label"><?php echo e(__('نوع السؤال')); ?></label>
                        <select class="form-select" name="question_type_id" id="question_type_id" required>
                            <option value="" disabled><?php echo e(__('اختر...')); ?></option>
                            <?php $__currentLoopData = $questionTypes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $type): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($type->id); ?>"
                                    data-slug="<?php echo e($type->slug); ?>"
                                    <?php if(old('question_type_id', $question->question_type_id) == $type->id): echo 'selected'; endif; ?>>
                                    <?php echo e($type->name); ?> (<?php echo e($type->slug); ?>)
                                </option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </div>

                    <div class="mb-3" id="expectedSafeWrap">
                        <label class="form-label"><?php echo e(__('الإجابة الآمنة المتوقعة')); ?></label>

                        <?php
                            $safeAnswer = old('expected_safe_answer');
                            if ($safeAnswer === null) {
                                $rawSafe = $question->getRawOriginal('expected_safe_answer');
                                if ($rawSafe === null) {
                                    $safeAnswerStr = '';
                                } else {
                                    $safeAnswerStr = $question->expected_safe_answer ? '1' : '0';
                                }
                            } else {
                                $safeAnswerStr = $safeAnswer;
                            }
                        ?>

                        <div class="d-flex gap-3">
                            <div class="form-check">
                                <input class="form-check-input" type="radio" name="expected_safe_answer" id="safe_yes" value="1"
                                    <?php if($safeAnswerStr === '1'): echo 'checked'; endif; ?>>
                                <label class="form-check-label" for="safe_yes"><?php echo e(__('نعم (1)')); ?></label>
                            </div>

                            <div class="form-check">
                                <input class="form-check-input" type="radio" name="expected_safe_answer" id="safe_no" value="0"
                                    <?php if($safeAnswerStr === '0'): echo 'checked'; endif; ?>>
                                <label class="form-check-label" for="safe_no"><?php echo e(__('لا (0)')); ?></label>
                            </div>

                            <div class="form-check">
                                <input class="form-check-input" type="radio" name="expected_safe_answer" id="safe_none" value=""
                                    <?php if($safeAnswerStr === ''): echo 'checked'; endif; ?>>
                                <label class="form-check-label" for="safe_none"><?php echo e(__('بدون')); ?></label>
                            </div>
                        </div>

                        <div class="form-text"><?php echo e(__('قيمته تُحفظ كـ 1 أو 0 (اختياري).')); ?></div>
                    </div>

                    <div class="d-flex justify-content-between">
                        <button class="btn btn-primary" type="submit"><?php echo e(__('حفظ التعديلات')); ?></button>
                        <a href="<?php echo e(route('questions.index')); ?>" class="btn btn-secondary"><?php echo e(__('إلغاء الرجوع للأسئلة')); ?></a>
                    </div>
                </form>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\xampp82\htdocs\GeneralProject-form\resources\views/questions/edit.blade.php ENDPATH**/ ?>