@extends('template.layout')

@section('content')
    @include('sweet::alert')

    <div class="portlet light portlet-fit portlet-datatable bordered">
        <div class="portlet-title">
            <div class="caption">
                <span class="caption-subject font-green sbold uppercase"> Asistencia Personal </span>
            </div>
        </div>
        <div class="portlet-body">

            <div class="row">
                <div class="col-lg-12">
                    <div class="col-lg-2">
                        <span class="caption-subject uppercase">Filtro por rol: </span>
                    </div>
                    <div class="col-lg-2">

                        <select class="bs-select form-control" id="selectRol">
                            <option value="">Todos</option>
                            @foreach($roles as $rol)
                                <option value="{{$rol->name}}">{{$rol->name}}</option>
                            @endforeach
                        </select>
                    </div>
                </div>
            </div>
            <div class="Forum-ForumTopicList row" style="margin:20px">
                <div class="col-lg-12" id="divTable">
                    <table class="table table-hover nowrap dataTable dtr-inline collapsed tbPersonal"
                           id="tbPersonal"
                           width="100%" role="grid" aria-describedby="tbPersonal_info">
                        <thead class="thead-default">
                        <tr>
                            <th>N°</th>
                            <th>DNI</th>
                            <th>Nombre</th>
                            <th>Roles</th>
                            <th>Opciones</th>
                        </tr>
                        </thead>
                        <tbody>
                        @php ($count = 1)
                        @foreach($users as $item)
                            <tr>
                                <td> {{ $count }} </td>
                                <td style="word-wrap: break-word; word-break: break-all; white-space: normal;"> {{ $item->nombre_completo }}</td>
                                <td> {{ $item->dni }} </td>
                                <td style="word-wrap: break-word; word-break: break-all; white-space: normal;">{{ $item->Roles }}</td>
                                <td>
                                    <a href="{{url('reportesasistencia/personal/asistencias',['id' => $item->id ])}}"
                                       class="btn btn-outline btn-circle btn-sm purple">
                                        Ver Asistencias
                                    </a>
                                    @if(str_contains($item->Roles,'Profesor'))
                                        <a href="{{url('reportesasistencia/personal/asistencias/cursos',['id' => $item->id ])}}"
                                           class="btn btn-outline btn-circle btn-sm purple">
                                            Asistencia por curso
                                        </a>
                                    @endif

                                </td>

                            </tr>
                            @php ($count++)
                        @endforeach
                        </tbody>
                    </table>
                </div>
            </div>


        </div>

    </div>


@endsection
@section('scripts')
    <script>


        var tbpersonal = $('#tbPersonal').DataTable({
            "lengthMenu": [[25, 20, 50, -1], [25, 20, 50, "Todas"]],
            bFilter: true,
            "bLengthChange": false,
            bInfo: true,
            responsive: true,
            "autoWidth": true,
            "language": {
                "lengthMenu": "Mostrar _MENU_ Entradas",
                "zeroRecords": "No se encontraron registros",
                "info": "Mostrando la página _PAGE_ de _PAGES_",
                "infoEmpty": "No hay registros disponibles",
                "infoFiltered": "(filtrado de _MAX_ registros totales)",
                "search": "Buscar: ",
                "paginate": {
                    "first": "Primero",
                    "last": "Último",
                    "next": "Siguiente",
                    "previous": "Anterior"
                },
            },
            "order": [],
            "aoColumns": [
                {"bSearchable": false},
                {"bSearchable": true},
                {"bSearchable": true},
                {"bSearchable": true},
                {"bSearchable": false},
            ],
            "columns": [
                {"orderable": false},
                {"orderable": true},
                {"orderable": true},
                {"orderable": true},
                {"orderable": false},
            ],
            dom: 'Bfrtip',
            buttons: [
                {
                    extend: 'excel',
                    exportOptions: {
                        columns: [ 0, 1, 2,3 ]
                    },
                    title: 'Listado personal'
                },{
                    extend: 'pdf',
                    exportOptions: {
                        columns: [ 0, 1, 2 ,3]
                    },
                    pageSize: 'LEGAL',
                    customize: function(doc) {
                        //pageMargins [left, top, right, bottom]
                        doc.pageMargins = [ 120, 20, 20, 20 ];
                    },
                    title: 'Listado personal'
                }

            ]
        });

        $("#selectRol").change(function () {
            tbpersonal.column(3)
                .search($("#selectRol").val() )
                .draw();
        });

    </script>
@endsection
