@extends('app')
@section('title', 'List school year')
@section('link')
    <!-- Data Table Css -->
    <link rel="stylesheet" href="{{asset('bower_components/datatables.net-bs4/css/dataTables.bootstrap4.min.css')}}">
    <link rel="stylesheet" href="{{asset('assets/pages/data-table/css/buttons.dataTables.min.css')}}">
    <link rel="stylesheet" href="{{asset('bower_components/datatables.net-responsive-bs4/css/responsive.bootstrap4.min.css')}}">
    <link rel="stylesheet" href="{{asset('assets/pages/data-table/extensions/autofill/css/autoFill.dataTables.min.css')}}">
    <link rel="stylesheet" href="{{asset('assets/pages/data-table/extensions/autofill/css/select.dataTables.min.css')}}">
    <style>
        .dataTables_length{
            display: none;
        }
        .btn.btn-icons {
            border-radius: 50%;
            width: 25px;
            line-height: 15px;
            height: 25px;
            padding: 2px;
            text-align: center;
        }
        .btn.btn-icons i{
            font-size: 11px;
            margin: 0px auto
        }
    </style>
@endsection
@section('content')
<div class="pcoded-inner-content">
    <div class="main-body">
        @include('includes._alert')
        <div class="page-wrapper">
            <div class="page-body">
                <div class="row">
                    <div class="col-sm-12">
                        <div class="card">
                            <div class="card-header mb-0 pb-0">
                                <div class="d-flex justify-content-between pb-2">
                                    <h4>School Year</h4>
                                    <span>
                                        <a href="{{route('school_year.create')}}" class="btn btn-inverse btn-outline-inverse  btn-sm py-1" title="Add New School Year"> <i class="fas fa-plus mx-0"></i></a>
                                    </span>
                                </div>
                            </div>
                            <hr class="my-0 mx-3">
                            <div class="card-block">
                                <div class="dt-responsive table-responsive">
                                    <table id="myTable" class="table table-striped table-bordered nowrap">
                                        <thead>
                                            <tr>
                                                <th class="text-center" style="width: 10%"></th>
                                                <th class="text-center" style="width: 25%">Année scolaire</th>
                                                <th class="text-center" style="width: 25%">Découpage</th>
                                                <th class="text-center" style="width: 20%">Status</th>
                                                <th class="text-center" style="width: 20%">Actions</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            @php $i = 1; @endphp
                                            @foreach ($datas as $item)
                                            <tr>
                                                <th class="text-center">{{$i <= 9 ? '0'.$i++:$i++}}</th>
                                                <td class="text-center">{{$item->school_year}}</td>
                                                <td class="text-center">{{ucwords($item->decoupage)}}</td>
                                                <td class="text-center">
                                                    <span class="pcoded-badge label label-{{$item->status ? 'success':'danger'}}">{{$item->status ? 'Actif':'Inactif'}}</span>
                                                </td>
                                                <td class="pt-3 pb-1">
                                                    <div class="card-block remove-label m-0 py-0 text-center">
                                                        <a href="{{route('school_year.edit',$item->id)}}" class="btn btn-inverse btn-outline-inverse btn-icons mx-1" title="Edit Year"><i class="fas fa-edit mx-0"></i></a>
                                                        <button class="btn btn-inverse btn-outline-inverse btn-icons mx-1 btnDelte" title="Delete Year" data-lib="{{ $item->school_year }}" data-id="{{ $item->id }}" {{$item->status ? 'disabled':''}}>
                                                            <i class="far fa-trash-alt mx-0"></i>
                                                        </button>
                                                    </div>
                                                </td>
                                            </tr>
                                            @endforeach
                                        </tbody>
                                    </table> 
                                </div> 
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- Modal -->
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog">
    <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content">
            <div class="modal-header bg-dark py-2">
                <h5 class="modal-title">Delete Year</h5>
                <i class="far fa-trash-alt mt-2" style="font-size: 17px"></i>
            </div>
            <div class="modal-body">
            <div class="row">
                <div class="col-12 text-center">
                    <p class="mb-2 mt-0">
                        <strong id="libelle" style="font-size: 19px"></strong>
                    </p>
                    <span>Confirmez la suppression de cette année</span>
                </div>
            </div>
            </div>
            <form action="{{ route('school_year.destroy') }}" method="post">
                @csrf
                <input type="hidden" name='year' id="years">
                <div class="modal-footer">
                    <a href="#" class="btn btn-inverse btn-outline-inverse btn-sm py-1 mx-2" data-dismiss="modal">Annuler</a>
                    <button type="submit" class="btn btn-inverse btn-outline-inverse btn-sm py-1 mx-2">Valider</button>
                </div>
            </form>
        </div>
    </div>
</div>
@include('includes._modal_simple')
@endsection
@section('script')
<script src="{{asset('bower_components/datatables.net/js/jquery.dataTables.min.js')}}"></script>
<script src="{{asset('bower_components/datatables.net-buttons/js/dataTables.buttons.min.js')}}"></script>
<script src="{{asset('assets/pages/data-table/js/jszip.min.js')}}"></script>
<script src="{{asset('assets/pages/data-table/js/pdfmake.min.js')}}"></script>
<script src="{{asset('assets/pages/data-table/js/vfs_fonts.js')}}"></script>
<script src="{{asset('assets/pages/data-table/extensions/autofill/js/dataTables.autoFill.min.js')}}"></script>
<script src="{{asset('assets/pages/data-table/extensions/autofill/js/dataTables.select.min.js')}}"></script>
<script src="{{asset('bower_components/datatables.net-buttons/js/buttons.print.min.js')}}"></script>
<script src="{{asset('bower_components/datatables.net-buttons/js/buttons.html5.min.js')}}"></script>
<script src="{{asset('assets/pages/data-table/js/dataTables.bootstrap4.min.js')}}"></script>
<script src="{{asset('bower_components/datatables.net-responsive/js/dataTables.responsive.min.js')}}"></script>
<script src="{{asset('bower_components/datatables.net-responsive-bs4/js/responsive.bootstrap4.min.js')}}"></script>
<!-- i18next.min.js -->
<script src="{{asset('bower_components/i18next/i18next.min.js')}}"></script>
<script src="{{asset('bower_components/i18next-xhr-backend/i18nextXHRBackend.min.js')}}"></script>
<script src="{{asset('bower_components/i18next-browser-languagedetector/i18nextBrowserLanguageDetector.min.js')}}"></script>
<script src="{{asset('bower_components/jquery-i18next/jquery-i18next.min.js')}}"></script>
<!-- Custom js -->
<script src="{{asset('assets/pages/data-table/extensions/autofill/js/extensions-custom.js')}}"></script>
<script src="{{asset('assets/js/pcoded.min.js')}}"></script>
<script src="{{asset('assets/js/vartical-layout.min.js')}}"></script>
<script src="{{asset('assets/js/jquery.mCustomScrollbar.concat.min.js')}}"></script>
<script>
    $('docemnt').ready(function(){

        $('#myTable').DataTable({
            ordering: false
        });
        

        $('.btnDelte').click(function() {
            $('#libelle').text($(this).data('lib'))
            $('#years').val($(this).data('id'));
            const editModal = new bootstrap.Modal(document.getElementById('deleteModal'));
            editModal.show();
        });
    });
</script>
@endsection