<?php $__env->startSection('content'); ?>

    <div class="row">
        <div class="col-xs-10">
            <h1>Form Response: <?php echo e($form->form->title); ?></h1>
            <p class="text-muted">Submitted on <?php echo e($form->created_at->setTimezone('Europe/Brussels')->format('d/m/Y H:i:s')); ?></p>
        </div>
        <?php if($canView): ?>
            <div class="col-xs-2">
                <a href="<?php echo e(url('/admin/form-responses')); ?>" class="back-btn btn btn-default" type="button" data-toggle="tooltip" data-placement="bottom" title="" class="btn btn-default pull-right" data-original-title="<?php echo e(trans('backend.back_list')); ?>">
                    <span class="icon glyphicon glyphicon-th-list"></span>
                </a>
            </div>
        <?php endif; ?>
    </div>

    <div id="view_form" class="generic_wrapper">
        <div class="row form-responses">
            <?php if($form->form->description): ?>
                <div class="col-xs-12">
                    <p class="form-description"><?php echo e($form->form->description); ?></p>
                </div>
            <?php endif; ?>

            <?php $__currentLoopData = $form->form->formSections; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $section): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <h2 class="col-xs-12"><?php echo e($section->title); ?></h2>

                <?php if($section->intro_text): ?>
                    <div class="col-xs-12">
                        <p class="section-intro"><?php echo e($section->intro_text); ?></p>
                    </div>
                <?php endif; ?>

                <?php $__currentLoopData = $section->formFields; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $field): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <?php
                        $fieldKey = "field_{$field->form_field_id}";
                        $responses = is_array($form->responses) ? $form->responses : (json_decode($form->responses, true) ?? []);
                        $fieldValue = $responses[$fieldKey] ?? null;
                    ?>

                    <?php if($fieldValue !== null && $fieldValue !== ''): ?>
                        <div class="col-xs-12 <?php echo e($field->layout === 'double' ? 'col-sm-6' : ''); ?>">
                            <span><strong><?php echo e($field->title); ?>:</strong></span>

                            <?php if($field->field_type === 'checkbox' && is_array($fieldValue)): ?>
                                
                                <ul class="checkbox-values">
                                    <?php $__currentLoopData = $fieldValue; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $selectedValue): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <?php
                                            $option = $field->fieldOptions->where('value', $selectedValue)->first();
                                            $displayValue = $selectedValue;
                                        ?>
                                        <li><?php echo e($displayValue); ?></li>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </ul>
                            <?php elseif($field->field_type === 'radio'): ?>
                                
                                <?php
                                    $option = $field->fieldOptions->where('value', $fieldValue)->first();
                                    $displayValue = $fieldValue;
                                ?>
                                <?php echo e($displayValue); ?>

                            <?php elseif($field->field_type === 'textarea'): ?>
                                
                                <div class="textarea-value"><?php echo nl2br(e($fieldValue)); ?></div>
                            <?php elseif($field->field_type === 'members'): ?>
                                
                                <?php
                                    $member = \App\Models\Member::full()
                                        ->select('members.*', 'member_languages.*')
                                        ->where('members.id', $fieldValue)
                                        ->first();
                                ?>
                                <?php echo e($member ? $member->title : $fieldValue); ?>

                            <?php else: ?>
                                
                                <?php echo e($fieldValue); ?>

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

            
            <h2 class="col-xs-12">Response Information</h2>
            <div class="col-xs-12 col-sm-6">
                <span><strong>Response ID:</strong></span> <?php echo e($form->id); ?>

            </div>
            <div class="col-xs-12 col-sm-6">
                <span><strong>Submitted at:</strong></span> <?php echo e($form->created_at->setTimezone('Europe/Brussels')->format('d/m/Y H:i:s')); ?>

            </div>
            <div class="col-xs-12 col-sm-6">
                <span><strong>Status:</strong></span>
                <?php if($form->isCancelled()): ?>
                    <span class="label label-danger">Cancelled</span>
                <?php else: ?>
                    <span class="label label-success">Confirmed</span>
                <?php endif; ?>
            </div>
            <?php if($form->cancelled_at): ?>
                <div class="col-xs-12 col-sm-6">
                    <span><strong>Cancelled at:</strong></span> <?php echo e($form->cancelled_at->setTimezone('Europe/Brussels')->format('d/m/Y H:i:s')); ?>

                </div>
            <?php endif; ?>
        </div>
    </div>

    <style>
        .form-description {
            background-color: #f8f9fa;
            padding: 15px;
            border-left: 4px solid #007bff;
            margin-bottom: 20px;
        }

        .section-intro {
            font-style: italic;
            color: #666;
            margin-bottom: 15px;
        }

        .checkbox-values {
            margin: 0;
            padding-left: 20px;
        }

        .textarea-value {
            background-color: #f8f9fa;
            padding: 10px;
            border-radius: 4px;
            margin-top: 5px;
        }

        .form-responses > div {
            margin-bottom: 15px;
        }

        .form-responses h2 {
            margin-top: 30px;
            margin-bottom: 20px;
            padding-bottom: 10px;
            border-bottom: 2px solid #eee;
        }
    </style>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('admin.layouts.main', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /var/www/html/resources/views/admin/pages/forms/form-responses-view.blade.php ENDPATH**/ ?>