<!-- Modal -->
<div class="modal fade" style="display:none" id="bookingModal" tabindex="-1" aria-labelledby="bookingModalLabel" aria-hidden="true" data-backdrop="static" data-keyboard="false">
    <div class="modal-dialog modal-dialog-centered modal-full">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="bookingModalLabel">แก้ไขตารางเรียน</h5>
            </div>
            <form action="{{ route('student.booking') }}"
                id="modalBookingFrm"
                novalidate class="{{ ($errors->any()) ? 'was-validated' : 'needs-validation' }}"
                method="post">
                @csrf
            <div class="modal-body">
                <input type="hidden" id="sid" name="sid" value="{{ $student->sid }}" >
                <input type="hidden" id="logStudent" name="logStudent" value="{{ $student->title.strip_tags($student->firstname)." ".strip_tags($student->lastname) }}" >
                <input type="hidden" id="vehicleType" value="{{ $student->courseType }}" >
                <input type="hidden" id="purpose" value="{{ $student->purpose }}" >
                <input type="hidden" id="enroll" name=enroll value="{{ $student->eid }}" >
                @for ($x = 0; $x < count($modules); $x++)
                <input type="hidden" id="vbid{{$x+1}}" name="vbid{{$x+1}}" @if(isset($bookings[$x])) value="{{ $bookings[$x]->vbid }}" @else value="0" @endif>
                <div class="row">
                    <div class="col-1">
                        <div class="form-group text-center">
                            <label for="drive1">ครั้งที่ {{$x+1}}</label>
                            <div class="icheck-nephritis">
                                <input type="checkbox" id="drive{{$x+1}}" name="drive{{$x+1}}" value="1" @isset($bookings[$x]) checked @endisset>
                                <label for="drive{{$x+1}}"></label>
                            </div>
                        </div>
                    </div>
                    <div class="col-1">
                        <div class="form-group">
                            <label for="gear{{$x+1}}">เกียร์ <span class="text-red">*</span></label>
                            <select id="gear{{$x+1}}" name="gear{{$x+1}}" class="selectpicker show-menu-arrow form-control" title="--เลือก--" disabled required>
                                <option value="ออโต้" @if(isset($bookings[$x]) && $bookings[$x]->gear=="ออโต้") selected @endif>ออโต้</option>
                                <option value="ธรรมดา" @if(isset($bookings[$x]) && $bookings[$x]->gear=="ธรรมดา") selected @endif>ธรรมดา</option>
                            </select>
                            @error('gear{{$x+1}}')
                            <div class="text-danger">{{  $message }}</div>
                            @enderror
                        </div>
                    </div>
                    <div class="col-2">
                        <div class="form-group">
                            <label for="date{{$x+1}}">วันที่ <span class="text-red">*</span></label>
                            <div class="input-group mb-3">
                                <input type="text" @isset($bookings[$x]) value="{{ formatDateFromDB($bookings[$x]->date) }}" @endisset class="form-control" id="date{{$x+1}}" name="date{{$x+1}}" placeholder="ครั้งที่ {{$x+1}}" autocomplete="off" disabled required>
                                <div class="input-group-append">
                                    <span class="input-group-text"><i class="far fa-calendar-alt"></i></span>
                                </div>
                            </div>
                            @error('date{{$x+1}}')
                            <div class="text-danger">{{  $message }}</div>
                            @enderror
                        </div>
                    </div>
                    <div class="col-1">
                        <div class="form-group">
                            <label for="starttime{{$x+1}}">เวลาเริ่ม <span class="text-red">*</span></label>
                            <select id="starttime{{$x+1}}" name="starttime{{$x+1}}" class="selectpicker show-menu-arrow form-control" title="--เลือก--" disabled required>
                                @for ($i = 7; $i < 21; $i++)
                                <option value="{{$i}}" @if(isset($bookings[$x]) && getHourDigit($bookings[$x]->starttime) == $i) selected @endif>{{ $i.":00"}}</option>
                                @endfor
                            </select>
                            @error('starttime{{$x+1}}')
                            <div class="text-danger">{{  $message }}</div>
                            @enderror
                        </div>
                    </div>
                    <div class="col-3">
                        <div class="form-group">
                            <label for="hour{{$x+1}}">รายวิชา <span class="text-red">*</span></label>
                            <select id="hour{{$x+1}}" name="hour{{$x+1}}" class="selectpicker show-menu-arrow form-control" title="--เลือก--" disabled required>
                                @foreach ($modules as $indexKey => $module)
                                <option value="{{ $module->id.'-'.$module->module_hour.'-'.$module->drive }}" @if(isset($bookings[$x]) && $bookings[$x]->course_module == $module->id) selected @endif>{{ "[". $module->module_hour ."] ".$module->module}}</option>
                                @endforeach
                            </select>
                            @error('hour{{$x+1}}')
                            <div class="text-danger">{{  $message }}</div>
                            @enderror
                        </div>
                    </div>
                    <div class="col-1">
                        <div class="form-group">
                            <label for="endtime{{$x+1}}">เวลาสิ้นสุด</label>
                            <input type="text" @isset($bookings[$x]) value="{{ formatTimeFromDB($bookings[$x]->endtime) }}" @endisset class="form-control" id="endtime{{$x+1}}" name="endtime{{$x+1}}" placeholder="เวลาสิ้นสุด" readonly>
                            @error('endtime{{$x+1}}')
                            <div class="text-danger">{{  $message }}</div>
                            @enderror
                        </div>
                    </div>
                    <div class="col-3">
                        <div class="form-group">
                            <label for="vehicle{{$x+1}}">รถ <span class="text-red">*</span></label>
                            <input type="hidden" id="driveType{{$x+1}}" @if(isset($bookings[$x])) value="{{ $bookings[$x]->drive }}" @endif>
                            <select id="vehicle{{$x+1}}" name="vehicle{{$x+1}}" class="selectpicker show-menu-arrow form-control" data-size="10" data-container="body" style="width:95%" title="--เลือก--" disabled required>
                                @isset($bookings[$x]) <option  value="{{$bookings[$x]->vid}}" selected>คันที่ : {{$bookings[$x]->number. " , " .$bookings[$x]->brand." ".$bookings[$x]->model. " (" .$bookings[$x]->registration_class ." ".$bookings[$x]->registration_number. ")"}}</option> @endisset
                            </select>
                            @error('vehicle{{$x+1}}')
                            <div class="text-danger">{{  $message }}</div>
                            @enderror
                        </div>
                    </div>
                </div>
                @endfor
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-outline-secondary" data-dismiss="modal">ปิด</button>
                <button type="submit" class="btn btn-success">แก้ไข</button>
            </div>
            </form>
        </div>
    </div>
</div>
