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

<div class="row">
    <div class="col-sm-3">
        @include('side_menu')
    </div>
    <div class="col-sm-9">
        <div class="row">
            <div class="col-sm-12 add-container">
                <form action="/questionnairesection/save" method="post" class="add-form">
                    <div class="container">
                        <div class="row">
                            @csrf
                            @if ($errors->any())
                            <div class="alert alert-danger" role="alert">
                                Please fix the following errors
                            </div>
                            @endif
                            @if($selectedQuestionnaireSection != null)
                            <input type="hidden" id="selected_questionnairesection" name="selected_questionnairesection" value="{{$selectedQuestionnaireSection->questionnaire_section_id}}" />
                            @endif
                            <div class="col-sm-9">
                                <div class="form-group">
                                    <label for="section_name">Section Name</label>
                                    <input type="text" class="form-control @error('section_name') is-invalid @enderror" id="section_name" name="section_name" placeholder="Name" value="@if($selectedQuestionnaireSection != null){{$selectedQuestionnaireSection->section_name}}@else{{ old('section_name') }}@endif">
                                    @error('section_name')
                                    <div class="invalid-feedback">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                            <div class="col-sm-9">
                                <div class="form-group">
                                    <label for="county">Part</label>
                                    <select class="form-control @error('questionnaire_part_id') is-invalid @enderror" id="questionnaire_part_id" name="questionnaire_part_id">
                                        <option value="">Select Part</option>
                                        @foreach($questionnaireparts as $questionnairepart)
                                        @if($selectedQuestionnaireSection != null)
                                            <option @if($selectedQuestionnaireSection->questionnaire_part_id == $questionnairepart->questionnaire_part_id) selected @endif value="{{$questionnairepart->questionnaire_part_id}}">{{$questionnairepart->part_name}}</option>
                                        @else
                                            <option value="{{$questionnairepart->questionnaire_part_id}}">{{$questionnairepart->part_name}}</option>
                                        @endif
                                        @endforeach
                                    </select>
                                    @error('title')
                                        <div class="invalid-feedback">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                            <div class="col-sm-9">
                                <button type="submit" class="btn btn-primary bt-margin">Save</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="container">
                <div class="row search-mg">
                    <div class="col-md-12 search-col">
                        <button class="btn float-right search-bt" onclick="searchQuestionnaireSections()">Search</button>
                        <input type="text" class="form-control float-right search-txt" id="search-questionnairesection" name="search-questionnairesection" placeholder="Search" />
                    </div>
                </div>
                <div class="row t-header">
                    <div class="col-5">Section Name</div>
                    <div class="col-5">Part</div>
                    <div class="col-2"></div>
                </div>
                <div id="questionnairesections-data">
                    @foreach ($questionnairesections as $questionnairesection)
                    <div class="row t-content">
                        <div class="col-5">
                            {{ $questionnairesection->section_name }}
                        </div>
                        <div class="col-5">
                            {{ $questionnairesection->questionnairePart->part_name }}
                        </div>
                        <div class="col-2 edit-butts">
                            <span>
                                <a href="/questionnairesection/edit/{{$questionnairesection->questionnaire_section_id}}">
                                    <img src="/images/edit.png" width="15px" alt="Edit" />
                                </a>
                                <button rel="{{$questionnairesection->questionnaire_section_id}}" class="btn delquestionnairesection" data-toggle="modal" data-target="#questionnairesectionsModal">
                                    <img src="/images/delete.png" width="15px" alt="Delete" />
                                </button>
                            </span>
                        </div>
                    </div>
                    @endforeach
                </div>
            </div>
        </div>
    </div>

    <!-- Modal -->
    <div class="modal fade" id="questionnairesectionsModal" tabindex="-1" role="dialog" aria-labelledby="questionnairesectionsModalLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="questionnairesectionsModalLabel">Confirm Delete</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    Are you sure you would like to delete the selected questionnaire section?
                </div>
                <div class="modal-footer">
                    <div class="row" style="width:100%">
                        <div class="col-8">
                            <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                        </div>
                        <div class="col-4">
                            <form action="/questionnairesection/del" method="post">
                                @csrf
                                <input type="hidden" id="del-questionnairesection" name="deletequestionnairesection" />
                                <button type="submit" class="btn btn-primary">Confirm</button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    @endsection