@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="/questionnairepart/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($selectedQuestionnairePart != null)
                            <input type="hidden" id="selected_questionnairepart" name="selected_questionnairepart" value="{{$selectedQuestionnairePart->questionnaire_part_id}}" />
                            @endif
                            <div class="col-sm-9">
                                <div class="form-group">
                                    <label for="part_name">Questionnaire Part</label>
                                    <input type="text" class="form-control @error('part_name') is-invalid @enderror" id="part_name" name="part_name" placeholder="Questionnaire Part" value="@if($selectedQuestionnairePart != null){{$selectedQuestionnairePart->part_name}}@else{{ old('part_name') }}@endif">
                                    @error('part_name')
                                    <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="searchQuestionnaireParts()">Search</button>
                        <input type="text" class="form-control float-right search-txt" id="search-questionnairepart" name="search-questionnairepart" placeholder="Search" />
                    </div>
                </div>
                <div class="row t-header">
                    <div class="col-6">Questionnaire Part</div>
                    <div class="col-6"></div>
                </div>
                <div id="questionnaireparts-data">
                    @foreach ($questionnaireparts as $questionnairepart)
                    <div class="row t-content">
                        <div class="col-6">
                            {{ $questionnairepart->part_name }}
                        </div>
                        <div class="col-6 edit-butts">
                            <span>
                                <a href="/questionnairepart/edit/{{$questionnairepart->questionnaire_part_id}}">
                                    <img src="/images/edit.png" width="15px" alt="Edit" />
                                </a>
                                <button rel="{{$questionnairepart->questionnaire_part_id}}" class="btn delquestionnairepart" data-toggle="modal" data-target="#questionnairepartsModal">
                                    <img src="/images/delete.png" width="15px" alt="Delete" />
                                </button>
                            </span>
                        </div>
                    </div>
                    @endforeach
                </div>
            </div>
        </div>
    </div>

    <!-- Modal -->
    <div class="modal fade" id="questionnairepartsModal" tabindex="-1" role="dialog" aria-labelledby="questionnairepartsModalLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="questionnairepartsModalLabel">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 part?
                </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="/questionnairepart/del" method="post">
                                @csrf
                                <input type="hidden" id="del-questionnairepart" name="deletequestionnairepart" />
                                <button type="submit" class="btn btn-primary">Confirm</button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
 @endsection