@extends('layouts.web')

@section('css')
<link href="{{ asset('css/dataTables.bootstrap4.min.css') }}" rel="stylesheet" />
<link href="{{ asset('css/sweetalert2.min.css') }}" rel="stylesheet" />
<link href="{{ asset('css/bootstrap-datepicker.min.css') }}" rel="stylesheet" />
@endsection

@section('content')
<div class="container-fluid pt-3">
    <div class="row mt-3">
        <div class="col">
            <div class="card card-outline card-success">
                <div class="card-header">
                    <h3 class="card-title text-bold">สรุปตารางวันที่ {{formatDateFromDB($date)}}</h3>
                </div>
                <div class="card-body table-responsive">
                    <table class="table" id="student-table">
                        <thead>
                          <tr>
                            <th scope="col" width="5%">#</th>
                            <th scope="col" width="10%">เลขที่</th>
                            <th scope="col" width="25%">ชื่อ-สกุล</th>
                            <th scope="col" width="26%">วิชา</th>
                            <th scope="col" width="10%">เวลา</th>
                            <th scope="col" width="10%">รถคันที่</th>
                            <th scope="col" width="9%"></th>
                          </tr>
                        </thead>
                        <tbody>
                            @foreach ($tomorrows as $indexKey => $tomorrow)
                            <tr class="hand-hover">
                                <td class="align-middle">{{ $indexKey + 1 }}.</td>
                                <td class="align-middle">{{ $tomorrow->code_no."/".$tomorrow->code_month."/".$tomorrow->code_branch }}</td>
                                <td class="align-middle">
                                    <a class="course-title-link" href="{{ route('student.show',$tomorrow->student_id) }}">
                                        {{ $tomorrow->firstname ." ". $tomorrow->lastname }}
                                    </a>
                                </td>
                                <td class="align-middle">{{ $tomorrow->module }}</td>
                                <td class="align-middle">{{ formatTimeFromDB($tomorrow->starttime) .' - '. formatTimeFromDB($tomorrow->endtime) }}</td>
                                <td class="align-middle">{{ "รถคันที่ ". $tomorrow->number }}</td>
                                <td class="align-middle text-center">
                                    <form id="del-frm{{ $indexKey }}" class="d-inline"
                                        action="{{ route('calendar.cancel_booking') }}"
                                        method="post"
                                        onsubmit="confirmalert(event, {{ $indexKey }}, 'ตารางเรียน')"
                                    >
                                        @csrf
                                        @method('DELETE')
                                        <input type="hidden" name="vehicleBookingID" id="vehicle-cancle-booking{{$indexKey}}" value="{{$tomorrow->vid}}">
                                        <div class="clearfix float-right" >
                                            <button type="submit" id="cancelBtn{{$indexKey}}" class="btn btn-danger" >ยกเลิกนัด</button>
                                        </div>
                                    </form>
                                </td>
                            </tr>
                            @endforeach
                        </tbody>
                      </table>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-12">
            <div style="float:left">
                <a href="{{ route('home.index') }}" class="btn btn-outline-secondary"><i class="fas fa-chevron-left"></i> ย้อนกลับ</a>
            </div>
        </div>
    </div>
</div>
@endsection

@section('footerscript')
<script src="{{ asset('js/sweetalert2.min.js') }}"></script>
<script src="{{ asset('js/jquery.dataTables.min.js') }}"></script>
<script src="{{ asset('js/dataTables.bootstrap4.min.js') }}"></script>
<script src="{{ asset('js/bootstrap-datepicker.min.js') }}"></script>
<script src="{{ asset('js/bootstrap-datepicker.th.min.js') }}"></script>
<script src="{{ asset('js/custom.js') }}"></script>
<script>
    $(document).ready(function() {
        $('#student-table').DataTable({
            "lengthChange": false,
            "info": false,
            "pageLength": 30,
            "language": {
                "emptyTable":   "ไม่พบข้อมูล",
                "paginate": {
                    "first":    "หน้าแรก",
                    "last":     "หน้าสุดท้าย",
                    "next":     "ถัดไป",
                    "previous": "ก่อนหน้า"
                },
                "search":       "ค้นหา:",
                "lengthMenu":   "จำนวนนักเรียนทั้งหมด _MENU_ คน",
                "info":         "ทั้งหมด _TOTAL_ คน",
                "infoEmpty":    "ไม่พบนักเรียน",
            }
        });

        $('#student-table tr td:not(:last-child)').click(function () {
            var href = $(this).closest('tr').find('a').attr('href');
            location.href = href;
        });

    });
</script>
@if (session('feedback'))
<script>
    Swal.fire({
                text: '{{ session('feedback') }}',
                icon: 'success',
                confirmButtonText: 'ตกลง',
                confirmButtonColor: '#62966C'
    })
</script>
@endif
@endsection

