@extends('layouts.web')

@section('css')
<link href="https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap4.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/sweetalert2@10.3.6/dist/sweetalert2.min.css" rel="stylesheet">
@endsection

@section('content')
<div class="container-fluid pt-3">
    @can('isSuperadminOrAdmin')
    <a href="{{ route('teacher.create') }}" class="btn btn-success rounded"><i class="fas fa-plus-circle"></i> เพิ่มผู้สอน</a>
    @endcan
    <div class="row mt-3">
        <div class="col">
            <div class="card card-outline card-success">
                <div class="card-body">
                    <table class="table" id="teacher-table">
                        <thead>
                          <tr>
                            <th scope="col" width="5%">ลำดับ</th>
                            <th scope="col" width="15%">ประเภท</th>
                            <th scope="col" width="10%">เพศ</th>
                            <th scope="col" width="25%">ชื่อ</th>
                            <th scope="col" width="10%">ชื่อเล่น</th>
                            <th scope="col" width="5%">อายุ</th>
                            <th scope="col" width="20%">หมายเลขโทรศัพท์</th>
                            @can('isSuperadminOrAdmin')
                            <th width="10%"></th>
                            @endcan
                          </tr>
                        </thead>
                        <tbody>
                            @foreach ($teachers as $indexKey => $teacher)
                            <tr class="hand-hover">
                                <td class="align-middle">{{ $indexKey + 1 }}.</td>
                                <td class="align-middle">{{ getTeacherType($teacher->type) }}</td>
                                <td class="align-middle">{{ $teacher->gender }}</td>
                                <td class="align-middle"><a href="{{ route('teacher.show',$teacher->id) }}" class="course-title-link">{{ $teacher->title.$teacher->firstname ." ". $teacher->lastname }}</a></td>
                                <td class="align-middle">{{ $teacher->nickname }}</td>
                                <td class="align-middle">{{ calAge($teacher->birthdate) }}</td>
                                <td class="align-middle">{{ $teacher->phone_1 }} @if($teacher->phone_2 != null) , {{ $teacher->phone_2 }} @endif</td>
                                @can('isSuperadminOrAdmin')
                                <td class="align-middle text-center">
                                    <a href="{{ route('teacher.edit',$teacher->id) }}" class="edit-btn ml-2" data-toggle="tooltip" data-placement="top" title="แก้ไขข้อมูล"><i class="far fa-edit"></i></a>
                                    <form id="del-frm{{ $indexKey }}" class="d-inline"
                                        method="POST"
                                        action="{{ route('teacher.destroy', $teacher->id ) }}"
                                        onsubmit="confirmalert(event, {{ $indexKey }}, 'ผู้สอน')"
                                    >
                                    @csrf
                                    @method('DELETE')
                                        <button type="submit" class="btn del-btn btn-sm ml-2" data-toggle="tooltip" data-placement="top" title="ลบข้อมูล">
                                            <i class="far fa-trash-alt"></i>
                                        </button>
                                    </form>
                                </td>
                                @endcan
                            </tr>
                            @endforeach
                        </tbody>
                      </table>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

@section('footerscript')
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@10.3.6/dist/sweetalert2.min.js"></script>
<script src="https://cdn.datatables.net/1.10.22/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.22/js/dataTables.bootstrap4.min.js"></script>
<script src="{{ asset('js/custom.js') }}"></script>
<script src="{{ asset('js/teacher.js') }}"></script>
@if (session('feedback'))
<script>
    Swal.fire({
                text: '{{ session('feedback') }}',
                icon: 'success',
                confirmButtonText: 'ตกลง',
                confirmButtonColor: '#62966C'
    })
</script>
@endif
@endsection

