<?php $__env->startSection('styles'); ?>
    <link href="<?php echo e(asset('plugins/datatables/datatables.min.css')); ?>" rel="stylesheet" type="text/css" />
    <link href="<?php echo e(asset('plugins/datatables/plugins/bootstrap/datatables.bootstrap.css')); ?>" rel="stylesheet" type="text/css" />
<?php $__env->stopSection(); ?>
<?php $__env->startSection('content'); ?>
    <h1 class="page-title">
        Libros perdidos
    </h1>

    <div class="portlet light bordered">
        <div class="portlet-title">
            <div class="caption">
                <h1 class="caption-subject font-green sbold uppercase"> Lista de libros perdidos</h1>
            </div>
            <div class="actions">
                <div class="btn-group">
                    <button class="btn blue btn-outline sbold " onclick="myModalShow()"> Registrar perdida</button>
                </div>
            </div>
        </div>
        <div class="portlet-body">
            <div class="row">
                <div class="col-lg-12">
                    <div class="Forum-ForumTopicList" style="margin:20px">
                        <table class="table table-hover nowrap dataTable dtr-inline collapsed tbPerdidos" id="tbPerdidos"
                               width="100%" role="grid" aria-describedby="tbPerdidos_info">
                            <thead class="thead-default">
                            <tr>
                                <th>N°</th>
                                <th>C&oacute;digo del ejemplar</th>
                                <th>Nombre bibliografia</th>
                                <th>Fecha de perdida</th>
                                <th>DNI Alumno</th>
                                <th>Nombre Alumno</th>
                                <th>Perdido</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php ($count = 1); ?>
                            <?php $__currentLoopData = $perdidas; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <tr>
                                    <td> <?php echo e($count); ?> </td>
                                    <td> <?php echo e($item->codigo_CS); ?> </td>
                                    <td> <?php echo e($item->nombre); ?> </td>
                                    <td> <?php echo e($item->fecha_perdida); ?> </td>
                                    <td> <?php echo e($item->dni); ?> </td>
                                    <td> <?php echo e($item->apellido_paterno); ?> <?php echo e($item->apellido_materno); ?>, <?php echo e($item->nombres); ?></td>
                                    <td>
                                        <div class="onoffswitch">
                                            <?php if($item->estado == 1): ?>
                                                <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox chk"
                                                       id="switch_<?php echo e($item->id); ?>" checked="checked">
                                            <?php else: ?>
                                                <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox chk"
                                                       id="switch_<?php echo e($item->id); ?>">
                                            <?php endif; ?>
                                            <label class="onoffswitch-label" for="switch_<?php echo e($item->id); ?>"
                                                   style="margin-bottom:0">
                                                <span class="onoffswitch-inner"></span>
                                                <span class="onoffswitch-switch"></span>
                                            </label>
                                        </div>
                                    </td>
                                </tr>
                                <?php ($count++); ?>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </tbody>
                        </table>
                    </div>

                </div>
            </div>
        </div>
    </div>

    <div id="RegistrarPerdidalModal" class="modal fade" tabindex="-1" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title">Registrar perdida</h4>
                </div>

                <?php echo Form::open(array('id' => 'form-validation','route' => array('perdida.crear'))); ?>

                <div class="modal-body" id="ModalBody">

                    <div class="form-group">
                        <?php echo Form::label('codigo_CS', 'Codigo libro:', ['class' => 'control-label']); ?>

                        <?php echo Form::text('codigo_CS', null, ['class' => 'form-control typeahead','required'=>'required']); ?>

                    </div>

                    <div class="form-group">
                        <?php echo Form::label('dni', 'DNI usuario:', ['class' => 'control-label']); ?>

                        <?php echo Form::text('dni', null, ['class' => 'form-control typeahead','required'=>'required']); ?>

                    </div>

                    <div class="form-group">
                        <?php echo Form::label('motivo', 'Motivo:', ['class' => 'control-label']); ?>

                        <?php echo Form::textarea('motivo', null, ['class' => 'form-control','required'=>'required','style'=>'resize:none;']); ?>

                    </div>

                    <div class="form-group">
                        <?php echo Form::label('fecha_perdida', 'Fecha perdida:', ['class' => 'control-label']); ?>

                        <?php echo Form::text('fecha_perdida', null, array('placeholder' => '','class' => 'form-control' ,'style' => 'resize:none;', 'required' => 'required')); ?>

                    </div>

                </div>
                <div class="modal-footer">
                    <button type="button" data-dismiss="modal" class="btn dark btn-outline">Cancelar</button>
                    <?php echo Form::submit('Guardar', ['class' => 'btn green']); ?>

                </div>
                <?php echo Form::close(); ?>

                <?php echo $__env->make('alerts.index', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>

            </div>
        </div>
    </div>

<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
    <script src="<?php echo e(asset('plugins/datatables/datatables.min.js')); ?>" type="text/javascript"></script>
    <script src="<?php echo e(asset('plugins/datatables/plugins/bootstrap/datatables.bootstrap.js')); ?>" type="text/javascript"></script>
    <script src="<?php echo e(asset('plugins/bootstrap-datepicker/js/bootstrap-datepicker.min.js')); ?>" type="text/javascript"></script>
    <script src="<?php echo e(asset('plugins/bootstrap-datepicker/locales/bootstrap-datepicker.es.min.js')); ?>" type="text/javascript"></script>
    <script src="<?php echo e(asset('plugins/jquery-validation/js/jquery.validate.min.js')); ?>" type="text/javascript"></script>
    <script src="<?php echo e(asset('plugins/jquery-validation/js/additional-methods.min.js')); ?>" type="text/javascript"></script>
    <script src="<?php echo e(asset('plugins/jquery-validation/js/localization/messages_es_PE.js')); ?>" type="text/javascript"></script>
    <script>
        $(function() {
            $( "#fecha_perdida" ).datepicker({ format:"yyyy-mm-dd", endDate: new Date(),language:"es" });
        });
        $("#form-validation").validate({
            rules: {
                dni: {
                    required:true,
                    pattern: '^[0-9]{8}$'
                }

            }
        });


        $('#tbPerdidos').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": false},
                {"bSearchable": true},
                {"bSearchable": true},
                {"bSearchable": false},

            ],
            "columns": [
                {"orderable": false},
                {"orderable": true},
                {"orderable": true},
                {"orderable": false},
                {"orderable": true},
                {"orderable": true},
                {"orderable": false},
            ],
            dom: 'Bfrtip',
            buttons: [
                {
                    extend: 'pdfs',
                    exportOptions: {
                        columns: [ 0, 1, 2, 3, 4, 5 ]
                    }
                },
                {
                    extend: 'excel',
                    exportOptions: {
                        columns: [ 0, 1, 2, 3, 4, 5 ]
                    }
                }
            ]
        });

        function myModalShow() {
            $('#RegistrarPerdidalModal').modal('show');
        }

        var posts = new Bloodhound({
            datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
            queryTokenizer: Bloodhound.tokenizers.whitespace,
            remote: {
                url: "<?php echo e(url('getdniusuario')); ?>" +"/%QUERY",
                wildcard: '%QUERY',
                transform: function(response) {
                    return $.map(response.data, function(user) {
                        return { value: user.dni };
                    });
                }
            }
        });

        $('#dni').typeahead({
                hint: false,
                highlight: true,
                minLength: 2,
                limit: 10
            },
            {
                name: 'posts',
                display: 'value',
                source: posts
            });

        var postsCod = new Bloodhound({
            datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
            queryTokenizer: Bloodhound.tokenizers.whitespace,
            remote: {
                url: "<?php echo e(url('getcodcibliografia')); ?>" +"/%QUERY",
                wildcard: '%QUERY',
                transform: function(response) {
                    return $.map(response.data, function(libro) {
                        return { value: libro.codigo_CS };
                    });
                }
            }
        });

        $('#codigo_CS').typeahead({
                hint: false,
                highlight: true,
                minLength: 2,
                limit: 10
            },
            {
                name: 'postsCod',
                display: 'value',
                source: postsCod
            });

        $('.chk').click(function () {
            var aux = this.id;
            var aux1 = aux.split("_");
            var id = aux1[1];

            $.ajax({
                url: "<?php echo e(url('perdidas/cambiarestado')); ?>" + "/" + id,

                context: document.body
            }).always(function() {
                swal("Se cambio el estado del ejemplar!");
            });
        });

    </script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('template.layout', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>