@extends('layouts.web')

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

@section('content')
@for ($a=0; $a<count($dd); $a++)
    {{ $dd[$a] }}
@endfor
<div class="container-fluid pt-3">
    <div class="row mt-3">
        <div class="col">
            <div class="card card-outline card-success">
                <div class="card-body">
                    <table class="table" id="student-table">
                        <thead>
                          <tr>
                            <th scope="col" width="5%">ลำดับ</th>
                            <th scope="col" width="8%">เลขที่</th>
                            <th scope="col" width="10%">วันที่สมัคร</th>
                            <th scope="col" width="20%">ชื่อ-สกุล</th>
                            <th scope="col" width="10%">โทรศัพท์</th>
                            <th scope="col" width="10%">โทรศัพท์(ฉุกเฉิน)</th>
                            <th scope="col" width="30%">หลักสูตร</th>
                            <th width="7%"></th>
                          </tr>
                        </thead>
                        <tbody>
                            @foreach ($students as $indexKey => $student)
                            <tr>
                                <td >{{ $indexKey + 1 }}.</td>
                                <td ><a href="{{ route('student.show',$student->id) }}" class="course-title-link">{{ $student->code_no."/".$student->code_month."/".$student->code_branch }}</a></td>
                                <td >{{ formatDateFromDB($student->register_date) }}</td>
                                <td ><a href="{{ route('student.show',$student->id) }}" class="course-title-link">{{ $student->firstname ." ". $student->lastname }}</a></td>
                                <td >{{ $student->phone_1 }} @if($student->phone_2 != null) , {{ $student->phone_2 }} @endif</td>
                                <td >{{ $student->emergency_phone }}</td>
                                <td >{{ "(".$student->type .") ". $student->name }}</td>
                                <td >
                                    <a href="{{ route('student.edit',$student->id) }}" class="edit-btn"><i class="far fa-edit"></i></a>
                                    <form id="del-frm{{ $indexKey }}" class="d-inline"
                                        method="POST"
                                        action="{{ route('student.destroy', $student->id ) }}"
                                        onsubmit="confirmalert(event, {{ $indexKey }}, 'นักเรียน')"
                                    >
                                    @csrf
                                    @method('DELETE')
                                        <button type="submit" class="btn del-btn btn-sm ml-2" >
                                            <i class="far fa-trash-alt"></i>
                                        </button>
                                    </form>
                                </td>
                            </tr>
                            @endforeach
                        </tbody>
                      </table>
                </div>
            </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/custom.js') }}"></script>
<script>
    $(document).ready(function() {
        $('#student-table').DataTable({
            "lengthChange": false,
            "info": false,
            "pageLength": 20,
            "language": {
                "emptyTable":   "ไม่พบข้อมูล",
                "paginate": {
                    "first":    "หน้าแรก",
                    "last":     "หน้าสุดท้าย",
                    "next":     "ถัดไป",
                    "previous": "ก่อนหน้า"
                },
                "search":       "ค้นหา:",
                "lengthMenu":   "จำนวนนักเรียนทั้งหมด _MENU_ คน",
                "info":         "ทั้งหมด _TOTAL_ คน",
                "infoEmpty":    "ไม่พบนักเรียน",
            }
        });
    });
</script>
@if (session('feedback'))
<script>
    Swal.fire({
                text: '{{ session('feedback') }}',
                icon: 'success',
                confirmButtonText: 'ตกลง',
                confirmButtonColor: '#62966C'
    })
</script>
@endif
@endsection

