<!-- Modal -->
<div class="modal fade" style="display:none" id="editBookingModal{{ $indexKey }}" tabindex="-1" aria-labelledby="editBookingModalLabel{{ $indexKey }}" 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="editBookingModalLabel{{ $indexKey }}">  แก้ไขตารางเรียน</h5>
            </div>
            <form action="{{ route('student.edit_booking') }}"
                id="modalEditBookingFrm{{ $indexKey }}"
                novalidate class="{{ ($errors->any()) ? 'was-validated' : 'needs-validation' }}"
                method="post">
                @csrf
            <div class="modal-body">
                <input type="hidden" id="sid{{ $indexKey }}" name="sid{{ $indexKey }}" value="{{ $student->sid }}" >
                <input type="hidden" id="logStudent{{ $indexKey }}" name="logStudent" value="{{ $student->title.strip_tags($student->firstname)." ".strip_tags($student->lastname) }}" >
                <input type="hidden" id="vehicleType{{ $indexKey }}" value="{{ $student->courseType }}" >
                <input type="hidden" id="purpose{{ $indexKey }}" value="{{ $student->purpose }}" >
                <input type="hidden" id="vbid{{ $indexKey }}" name="vbid{{ $indexKey }}" value="{{ $booking->vbid }}" >

                    <div class="row" id="addBookingRow">
                        <div class="col-1">
                            <div class="form-group">
                                <label for="gear{{ $indexKey }}">เกียร์ <span class="text-red">*</span></label>
                                <select id="gear{{ $indexKey }}" name="gear{{ $indexKey }}" class="selectpicker show-menu-arrow form-control" title="--เลือก--" required>
                                    <option value="ออโต้" @if(isset($booking) && $booking->gear=="ออโต้") selected @endif>ออโต้</option>
                                    <option value="ธรรมดา" @if(isset($booking) && $booking->gear=="ธรรมดา") selected @endif>ธรรมดา</option>
                                </select>
                                @error('gear')
                                <div class="text-danger">{{  $message }}</div>
                                @enderror
                            </div>
                        </div>
                        <div class="col-2">
                            <div class="form-group">
                                <label for="date{{ $indexKey }}">วันที่ <span class="text-red">*</span></label>
                                <div class="input-group mb-3">
                                    <input type="text" class="form-control" id="date{{ $indexKey }}" name="date{{ $indexKey }}" placeholder="วันที่ " value="{{ formatDateFromDB($booking->date) }}" autocomplete="off"  required>
                                    <div class="input-group-append">
                                        <span class="input-group-text"><i class="far fa-calendar-alt"></i></span>
                                    </div>
                                </div>
                                @error('date{{ $indexKey }}')
                                <div class="text-danger">{{  $message }}</div>
                                @enderror
                            </div>
                        </div>
                        <div class="col-1">
                            <div class="form-group">
                                <label for="starttime{{ $indexKey }}">เวลาเริ่ม <span class="text-red">*</span></label>
                                <select id="starttime{{ $indexKey }}" name="starttime{{ $indexKey }}" data-size="10" data-container="body" class="selectpicker show-menu-arrow form-control" title="--เลือก--"  required>
                                    @for ($i = 7; $i < 21; $i++)
                                    <option value="{{$i}}" @if(getHourDigit($booking->starttime) == $i) selected @endif>{{ $i.":00"}}</option>
                                    @endfor
                                </select>
                                @error('starttime{{ $indexKey }}')
                                <div class="text-danger">{{  $message }}</div>
                                @enderror
                            </div>
                        </div>
                        <div class="col-4">
                            <div class="form-group">
                                <label for="hour{{ $indexKey }}">รายวิชา<span class="text-red">*</span></label>
                                <select id="hour{{ $indexKey }}" name="hour{{ $indexKey }}" class="selectpicker show-menu-arrow form-control" title="--เลือก--"  required>
                                    @foreach ($modules as $indexKeyModule => $module)
                                    <option value="{{ $module->id.'-'.$module->module_hour.'-'.$module->drive }}" @if($booking->course_module == $module->id) selected @endif >{{ "[". $module->module_hour ."] ".$module->module}}</option>
                                    @endforeach
                                </select>
                                @error('hour{{ $indexKey }}')
                                <div class="text-danger">{{  $message }}</div>
                                @enderror
                            </div>
                        </div>
                        <div class="col-1">
                            <div class="form-group">
                                <label for="endtime{{ $indexKey }}">เวลาสิ้นสุด</label>
                                <input type="text" class="form-control" value="{{ formatTimeFromDB($booking->endtime) }}" id="endtime{{ $indexKey }}" name="endtime{{ $indexKey }}" placeholder="เวลาสิ้นสุด" readonly>
                                @error('endtime{{ $indexKey }}')
                                <div class="text-danger">{{  $message }}</div>
                                @enderror
                            </div>
                        </div>

                        <div class="col-3">
                            <div class="form-group">
                                <label for="vehicle{{ $indexKey }}">รถ <span class="text-red">*</span></label>
                                <select id="vehicle{{ $indexKey }}" name="vehicle{{ $indexKey }}" data-size="10" data-container="body" class="selectpicker show-menu-arrow form-control" title="--เลือก--"  required>
                                    <option  value="{{$booking->vid}}" selected>คันที่ : {{$booking->number. " , " .$booking->brand." ".$booking->model. " (" .$booking->registration_class ." ".$booking->registration_number. ")"}}</option>
                                </select>
                                @error('vehicle{{ $indexKey }}')
                                <div class="text-danger">{{  $message }}</div>
                                @enderror
                            </div>
                        </div>
                    </div>
            </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>
<!-- end modal -->
