

<?php $__env->startSection('content'); ?>
<section class="content-header">
    <div class="container-fluid">
        <div class="row mb-2">
            <div class="col-sm-6">
                <h1>View Submitted Form</h1>
            </div>
            <div class="col-sm-6">
                <ol class="breadcrumb float-sm-right">
                    <li class="breadcrumb-item"><a href="#">Home</a></li>
                    <li class="breadcrumb-item active">View Submitted Form</li>
                </ol>
            </div>
        </div>
    </div>
</section>

<section class="content">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card card-primary card-tabs">
                <div class="card-header">
                    <h3 class="card-title"><?php echo e($submittedForm->form->title); ?></h3>
                </div>
                <div class="card-body">
                    <div class="form-group">
                        <label>Submitted By:</label>
                        <p><?php echo e($submittedForm->created_by); ?></p>
                    </div>
                    <div class="form-group">
                        <label>Form ID:</label>
                        <p><?php echo e($submittedForm->id_form); ?></p>
                    </div>
                    <div class="form-group">
                        <label>Status:</label>
                        <p><?php echo e($submittedForm->form_status->title ?? 'N/A'); ?></p>
                    </div>

                    <!-- Display the form sections, questions, and submitted answers -->
                    <?php $__currentLoopData = $sections; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $section): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <div class="form-section mb-4">
                            <div class="card card-warning">
                                <div class="card-header">
                                    <h6><?php echo e($section->title); ?></h6>
                                </div>
                            </div>

                            <?php $__currentLoopData = $section->form_question; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $question): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <div class="form-group">
                                    <label for="question_<?php echo e($question->id); ?>">
                                        <?php echo e($question->tittle_numbering); ?>. <?php echo e($question->question); ?>

                                    </label>

                                    <!-- Display the answer based on question type -->
                                    <?php
                                        $answers = $submittedForm->form_answer->where('id_form_question', $question->id);
                                    ?>

                                    <?php switch($question->answer_type):
                                        case ('text'): ?>
                                        <?php case ('textarea'): ?>
                                        <?php case ('number'): ?>
                                        <?php case ('date'): ?>
                                            <p><?php echo e($answers->first()->value ?? 'No answer provided'); ?></p>
                                            <?php break; ?>

                                        <?php case ('select'): ?>
                                        <?php case ('radio'): ?>
                                        <?php case ('dropdown'): ?> <!-- Added dropdown case -->
                                            <p><?php echo e($answers->first()->value ?? 'No answer provided'); ?></p>
                                            <?php break; ?>
                                            
                                        <?php case ('checkbox'): ?>
                                            <?php if($answers->isNotEmpty()): ?>
                                                <ul>
                                                    <?php $__currentLoopData = $answers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $answer): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                        <li><?php echo e($answer->value); ?></li>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                </ul>
                                            <?php else: ?>
                                                <p>No answer provided</p>
                                            <?php endif; ?>
                                            <?php break; ?>

                                        <?php case ('file'): ?>
                                            <?php if($answers->first()): ?>
                                                <a href="<?php echo e(asset('storage/' . $answers->first()->value)); ?>" target="_blank">View File</a>
                                            <?php else: ?>
                                                <p>No file uploaded</p>
                                            <?php endif; ?>
                                            <?php break; ?>

                                        <?php case ('custom_ui'): ?>
                                            <!-- Handle the custom UI case with crop and area -->
                                            <table class="table table-bordered">
                                                <thead>
                                                    <tr>
                                                        <th>Komoditi</th>
                                                        <th>Jenis tanaman</th>
                                                        <th>Keluasan bertanam (ha)</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <?php
                                                        $crops = [
                                                            'fruits' => 24,
                                                            'vegetables' => 25,
                                                            'paddy' => 26,
                                                            'others' => 27
                                                        ];
                                                    ?>
                                                    <?php $__currentLoopData = $crops; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $crop => $questionId): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                        <?php
                                                            $cropAnswer = $submittedForm->form_answer->where('id_form_question', $questionId)->firstWhere('remarks', $submittedForm->created_by);
                                                        ?>
                                                        <tr>
                                                            <td><?php echo e(ucfirst($crop)); ?></td>
                                                            <td><?php echo e($cropAnswer->value ?? 'No answer provided'); ?></td>
                                                            <td><?php echo e($submittedForm->form_answer->where('id_form_question', $questionId)->where('remarks', $submittedForm->created_by)->pluck('value')->skip(1)->first() ?? 'No answer provided'); ?></td>
                                                        </tr>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                </tbody>
                                            </table>
                                            <?php
                                                $totalAreaAnswer = $submittedForm->form_answer->firstWhere('id_form_question', $question->id);
                                            ?>
                                            <p><strong>Total Planted Area:</strong> <?php echo e($totalAreaAnswer->value ?? 'Not provided'); ?> ha</p>
                                            <?php break; ?>

                                        <?php default: ?>
                                            <p>Unknown question type</p>
                                    <?php endswitch; ?>
                                </div>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </div>
            </div>
        </div>
    </div>
</section>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\laragon\www\VPS_changes\resources\views/form/form-view-answer.blade.php ENDPATH**/ ?>