@extends('layouts.app')
@section('content')

<script>
    $(document).ready(function() {

        ClassicEditor.create(document.querySelector('.preview_txt'))
            .then(editor => {
                console.log(editor);
            }).catch(error => {
                console.error(error);
            });
    });
</script>

<div class="row">
    <div class="col-sm-12">
        <div class="row">
            <div class="col-sm-12 add-container">
                <div class="container">
                    <div class="row" style="margin: 0;">
                        <div class="col-sm-11">
                        <form name="questionnaire-form" method="POST" action="/stakeholders/questionnaire/save">
                            @csrf
                            <ol class="quiz-ol">
                                <?php $counter = 0; ?>
                                @foreach($questionnaires as $questionnaire)
                                @if($counter == 0)
                                <?php $questionnaire_part_id = $questionnaire->questionnaire_part_id; ?>
                                <?php $questionnaire_section_id = $questionnaire->questionnaire_section_id; ?>
                                <?php $questionnaire_part = \App\Models\QuestionnairePart::find($questionnaire_part_id); ?>
                                <?php $questionnaire_section = \App\Models\QuestionnaireSection::find($questionnaire_section_id); ?>
                                <div class="part-header">
                                    <?php echo $questionnaire_part->part_name; ?>
                                </div>
                                <div class="section-header">
                                    <?php echo $questionnaire_section->section_name; ?>
                                </div>
                                @endif
                                <li>
                                    <div style="margin-top: 10px;">
                                        <?php echo $questionnaire->question; ?>
                                    </div>
                                    @if($questionnaire->feedback_area == 1)
                                    <textarea class="form-control preview_txt" style="width: 100%;height:70px;" id="textarea-<?php echo $questionnaire->questionnaire_id; ?>" name="textarea-<?php echo $questionnaire->questionnaire_id; ?>"></textarea>
                                    @endif
                                    @if($questionnaire->checkbox_options != null)
                                    <?php $checkboxOptions = explode(",", $questionnaire->checkbox_options); ?>
                                    <?php $count = 0; ?>
                                    @foreach($checkboxOptions as $option)
                                    <?php $count++; ?>
                                    <div class="col-4">
                                        <input type="checkbox" id="checkbox-<?php echo $questionnaire->questionnaire_id . "-" . $count; ?>" name="checkbox-<?php echo $questionnaire->questionnaire_id; ?>" value="<?php echo $option; ?>">
                                        <label for="checkbox-<?php echo $questionnaire->questionnaire_id . "-" . $count; ?>"> <?php echo $option; ?></label>
                                    </div>
                                    @endforeach
                                    @endif
                                    @if($questionnaire->needs_upload == 1)
                                    <input class="form-control" style="padding: 10px 0px 35px 10px;" type="file" id="file-<?php echo $questionnaire->questionnaire_id; ?>" name="file-<?php echo $questionnaire->questionnaire_id."[]"; ?>" multiple />
                                    @endif
                                    <!-- TO DO: For Dropdown -->

                                    <?php $questionnaire_tables = \App\Models\QuestionnaireTable::where('questionnaire_id', '=', $questionnaire->questionnaire_id)->get(); ?>
                                    @if($questionnaire_tables != null)
                                    @foreach($questionnaire_tables as $table)
                                    <div class="table-answers" style="margin: 10px 0px 0px 37px;">
                                        <?php echo $table->table_title; ?>
                                    </div>
                                    <?php echo $table->table_js; ?>
                                    <div style="margin-left:23px;">
                                    <?php echo $table->table_html; ?>
                                    </div>
                                    @endforeach
                                    @endif
                                    <!-- Sub Questionnaire -->
                                    <?php $subquestionnaires = \App\Models\SubQuestionnaire::where('questionnaire_id', '=', $questionnaire->questionnaire_id)->get(); ?>
                                    @if($subquestionnaires != null)
                                    <ol type="a">
                                        @foreach($subquestionnaires as $subquestionnaire)
                                        <li>
                                            <?php echo $subquestionnaire->sub_question; ?>
                                            @if($subquestionnaire->feedback_area == 1)
                                            <textarea class="form-control preview_txt" style="width: 100%;height:70px;" id="sub-textarea-<?php echo $subquestionnaire->sub_questionnaire_id; ?>" name="sub-textarea-<?php echo $subquestionnaire->sub_questionnaire_id; ?>"></textarea>
                                            @endif
                                            @if($subquestionnaire->checkbox_options != null)
                                            <?php $subCheckboxOptions = explode(",", $subquestionnaire->checkbox_options); ?>
                                            <?php $sub_count = 0; ?>
                                            @foreach($subCheckboxOptions as $option)
                                            <?php $sub_count++; ?>
                                            <div class="col-4">
                                                <input type="checkbox" id="sub-checkbox-<?php echo $subquestionnaire->sub_questionnaire_id . "-" . $sub_count; ?>" name="sub-checkbox-<?php echo $subquestionnaire->sub_questionnaire_id; ?>" value="<?php echo $option; ?>" />
                                                <label for="sub-checkbox-<?php echo $subquestionnaire->sub_questionnaire_id . "-" . $sub_count; ?>"> <?php echo $option; ?></label>
                                            </div>
                                            @endforeach
                                            @endif
                                            @if($subquestionnaire->needs_upload == 1)
                                            <input class="form-control" style="padding: 10px 0px 35px 10px;" type="file" id="sub-file-<?php echo $subquestionnaire->sub_questionnaire_id; ?>" name="sub-file-<?php echo $subquestionnaire->sub_questionnaire_id."[]"; ?>" multiple />
                                            @endif

                                            <?php $sub_questionnaire_tables = \App\Models\QuestionnaireTable::where('sub_questionnaire_id', '=', $subquestionnaire->sub_questionnaire_id)->get(); ?>
                                            @if($sub_questionnaire_tables != null)
                                            @foreach($sub_questionnaire_tables as $table)
                                            <div class="table-answers" style="margin: 10px 0px 0px 37px;">
                                                <?php echo $table->table_title; ?>
                                            </div>
                                            <?php echo $table->table_js; ?>
                                            <?php echo $table->table_html; ?>
                                            @endforeach
                                            @endif
                                            <!-- TO DO: For Dropdown -->

                                            <!-- Sub Sub Questionnaire -->
                                            <?php $sub_subquestionnaires = \App\Models\SubQuestionnaire::where('parent_sub_questionnaire_id', '=', $subquestionnaire->sub_questionnaire_id)->get(); ?>

                                            @if($sub_subquestionnaires != null)
                                            <ol type="i">
                                                @foreach($sub_subquestionnaires as $sub_subquestionnaire)
                                                <li>
                                                    <?php echo $sub_subquestionnaire->sub_question; ?>
                                                    @if($sub_subquestionnaire->feedback_area == 1)
                                                    <textarea class="form-control preview_txt" style="width: 100%;height:70px;" id="sub-sub-textarea-<?php echo $sub_subquestionnaire->sub_questionnaire_id; ?>" name="sub-sub-textarea-<?php echo $sub_subquestionnaire->sub_questionnaire_id; ?>"></textarea>
                                                    @endif
                                                    @if($sub_subquestionnaire->checkbox_options != null)
                                                    <?php $subSubCheckboxOptions = explode(",", $sub_subquestionnaire->checkbox_options); ?>
                                                    <?php $sub_sub_count = 0; ?>
                                                    @foreach($subSubCheckboxOptions as $option)
                                                    <?php $sub_sub_count++; ?>
                                                    <div class="col-4">
                                                        <input type="checkbox" id="sub-sub-checkbox-<?php echo $sub_subquestionnaire->sub_questionnaire_id . "-" . $sub_sub_count; ?>" name="sub-sub-checkbox-<?php echo $sub_subquestionnaire->sub_questionnaire_id; ?>" value="<?php echo $option; ?>" />
                                                        <label for="sub-sub-checkbox-<?php echo $sub_subquestionnaire->sub_questionnaire_id . "-" . $sub_sub_count; ?>"> <?php echo $option; ?></label>
                                                    </div>
                                                    @endforeach
                                                    @endif
                                                    @if($sub_subquestionnaire->needs_upload == 1)
                                                    <input class="form-control" style="padding: 10px 0px 35px 10px;" type="file" id="sub-sub-file-<?php echo $sub_subquestionnaire->sub_questionnaire_id; ?>" name="sub-sub-file-<?php echo $sub_subquestionnaire->sub_questionnaire_id."[]"; ?>" multiple />
                                                    @endif
                                                    <!-- TO DO: For Dropdown -->

                                                </li>
                                                <?php $sub_sub_questionnaire_tables = \App\Models\QuestionnaireTable::where('sub_questionnaire_id', '=', $sub_subquestionnaire->sub_questionnaire_id)->get(); ?>
                                                @if($sub_sub_questionnaire_tables != null)
                                                @foreach($sub_sub_questionnaire_tables as $table)
                                                <div class="table-answers" style="margin: 10px 0px 0px 37px;">
                                                    <?php echo $table->table_title; ?>
                                                </div>
                                                <?php echo $table->table_js; ?>
                                                <?php echo $table->table_html; ?>
                                                @endforeach
                                                @endif
                                                @endforeach
                                            </ol>
                                            @endif
                                        </li>
                                        @endforeach
                                    </ol>
                                    @endif
                                </li>
                                <?php $counter++; ?>
                                @endforeach
                            </ol>
                            <div class="row">
                                <div class="col-6">
                                    <button class="btn search-bt" style="margin-bottom: 10px;">
                                        Save
                                    </button>
                                </div>
                                <div class="col-6">
                                    <button class="btn btn-primary bt-margin float-right">
                                        Submit
                                    </button>
                                </div>
                            </div>
                        </form>
                        </div>
                        <div class="col-sm-1" style="padding: 0;">
                            <a href="/stakeholders">
                                <button title="Closes Without Saving!" class="float-right search-bt" style="padding: 3px 8px;font-size: 14px;" >X</button>
                            </a>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>

</div>
@endsection