<?php $__env->startSection('page-title'); ?> <?php echo e($model->getLabel()); ?> <?php $__env->stopSection(); ?>

<?php $__env->startSection('tag-title'); ?> <?php echo e($model->getLabel()); ?> <?php $__env->stopSection(); ?>

<?php $__env->startSection('page-sub-title'); ?>

    <?php if(in_array('add',$model->getActions())): ?>

        <a id="btn-export-excel" class="btn btn-info action-btn  pull-right text-white modal-effect" data-effect="effect-slide-in-right">
            <i class="fa fa-download"></i> Export to Excel
        </a>

        <?php if(empty($model->getViewForm())): ?>
            <a id="modal-crud-form-opener" data-target="#crud-form-modal"  data-toggle="modal" data-backdrop="static" data-keyboard="false" class="btn btn-primary action-btn  pull-right text-white modal-effect" data-effect="effect-slide-in-right">
                <i class="fa fa-plus"></i> <?php echo e($model->getAddBtnLabel()); ?>

            </a>
        <?php else: ?>
            <a href="<?php if(empty($model->getViewFormUrl())): ?><?php echo e(url(Request::path().'/add')); ?><?php else: ?><?php echo e(url($model->getViewFormUrl())); ?><?php endif; ?>" class="btn btn-primary action-btn pull-right text-white" >
                <i class="fa fa-plus"></i> <?php echo e($model->getAddBtnLabel()); ?>

            </a>
        <?php endif; ?>

    <?php else: ?>
        <?php echo e($model->getSubLabel()); ?>

    <?php endif; ?>

    <?php $__currentLoopData = $model->getCustomSingleActions(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $b): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
        <?php echo $model->$b(); ?>

    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

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

<?php $__env->startSection('main-content'); ?>
    <?php if(empty($model->getViewForm())): ?>
        <?php echo $__env->make('inc.cruds.modal_form', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
    <?php endif; ?>
    <div class="row">
        <?php if(count($model->getSearchFields())!=0): ?>
            <div class="col-xl-12">
                <div class="card">
                    <div class="card-header pb-0">
                        <div class="d-flex justify-content-between">
                            <h4 class="card-title mg-b-0">Search</h4>
                        </div>
                    </div>

                    <div class="card-body">

                    </div>
                </div>
            </div>
        <?php endif; ?>

            <?php
            $columnTitles = array_values($model->getFields());
            $columnKey = array_keys($model->getFields());
            ?>

            <div class="col-xl-12">
                <div class="card">

                    <div class="card-body">
                        <div class="table-responsive">
                            <table class="table  data-table  table-bordered table-hover">
                                <thead>
                                <tr>
                                    <?php $__currentLoopData = $columnTitles; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $columnTitle): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <?php $key = $key = array_search($columnTitle,$model->getFields()); ?>
                                        <?php if(!in_array($key,$model->getColumnsHiddens())): ?>
                                            <th class="border-bottom-0"><?php echo e($columnTitle); ?></th>
                                        <?php endif; ?>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    <?php if((count($model->getActions())!=0 || count($model->getCustomBouttons())!=0) && $model->isShowactionColumn()): ?>
                                        <th style="width: 10%; border-right: none;">Actions</th>
                                    <?php endif; ?>
                                </tr>
                                </thead>

                            </table>


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


<?php $__env->startSection('page-style'); ?>
    <link href="<?php echo e(url('assets/plugins/datatable/css/jquery.dataTables.min.css')); ?>" rel="stylesheet">
    <style>
        .card-body{
            padding: 10px;
        }
    </style>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('page-script'); ?>
    <script src="<?php echo e(url('assets/plugins/datatable/js/jquery.dataTables.min.js')); ?>"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.13.4/xlsx.core.min.js"></script>
    <script src="<?php echo e(url('assets/plugins/export-to-excel/jhxlsx.js')); ?>"></script>
    <script src="<?php echo e(url('assets/plugins/export-to-excel/FileSaver.js')); ?>"></script>
    <script src="<?php echo e(url('assets/plugins/export-to-excel/Blob.js')); ?>"></script>

    <script !src="">
        $(function(e) {
            <?php if(!empty($model->getAjaxListUrl())): ?>
                var data_ajax_url = '<?php echo e(url($model->getAjaxListUrl())); ?>';
            <?php else: ?>
                var data_ajax_url = '<?php echo e(url(Request::path().'/ajax_list?current_path='.Request::path())); ?>';
            <?php endif; ?>
            $('.data-table').DataTable({
                pageLength: 25,
                responsive: true,
                processing : true,
                serverSide: true,
                ajax: data_ajax_url,
                destroy : true,
                ordering: false,
                language: {
                    searchPlaceholder: 'Search...',
                    sSearch: '',
                    lengthMenu: '_MENU_',
                    sProcessing : "Loading..."
                },
            });

            $(document).on('click','#btn-export-excel',function (e) {
                e.preventDefault();
                $('#btn-export-excel').html('<i class="fa fa-spinner fa-spin fa-fw text-white"></i>');
                var excelUrl =  '<?php echo e(url(Request::path().'/ajax_list?excel=1')); ?>';
                var req = $.ajax({
                    url: excelUrl,
                    type: "GET",
                    data: {},
                    dataType: "json"
                });
                req.done(function (response, textStatus, jqXHR) {
                    var options = {
                        fileName:"<?php echo e(env('APP_NAME')); ?> - <?php echo e(\Illuminate\Support\Str::slug($model->getLabel())); ?>",
                        extension:".xlsx",
                        header:true,
                        fileFullName:"<?php echo e(\Illuminate\Support\Str::slug($model->getLabel())); ?>.xlsx",
                    };
                    Jhxlsx.export(response, options);
                    $('#btn-export-excel').html('<i class="fa fa-download"></i> Export to Excel');
                });
                req.fail(function (jqXHR, textStatus) {
                    swal("Erreur!", "Error during operation.", "warning");
                });
            });

            <?php $__currentLoopData = $model->getFormRequireds(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $input_required): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

            $("label[for='<?php echo e($input_required); ?>']").append('<span class="required"> *</span>');

            <?php if(!in_array($input_required, $model->getRichTexts()) && !in_array($input_required, $model->getFiles())): ?>
            $('#<?php echo e($input_required); ?>').attr('required', true);
            <?php endif; ?>

            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

            $(document).on('click','.btn-edit-record',function (e) {
                e.preventDefault();
                var href_modifieur = $(this).attr('href');

                var req = $.ajax({
                    url: href_modifieur,
                    type: "GET",
                    data: {param: ''},
                    dataType: "JSON"
                });

                req.done(function (response, textStatus, jqXHR) {
                    if(response!=null){
                        <?php
                        $primaryKey = $model->getPrimaryKey();
                        ?>
                        $('#_id').val(response.model.<?php echo e($primaryKey); ?>);
                        <?php $__currentLoopData = $columnKey; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $id): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <?php if(!in_array($id,$model->getFiles())): ?>
                                <?php if(in_array($id,$model->getLongTexts())): ?>
                                    $('#<?php echo e($id); ?>').html(response.model.<?php echo e($id); ?>);
                                <?php elseif(in_array($id,array_keys($model->getBelongsTo()))): ?>
                                    <?php
                                        $refrences = $model->getBelongsTo()[$id];
                                        $fkKey = $refrences[1];
                                    ?>
                                    $('#<?php echo e($fkKey); ?>').val(response.model.<?php echo e($fkKey); ?>);
                                <?php elseif(in_array($id,$model->getDates())): ?>
                                    $('#<?php echo e($id); ?>').val(formaDate(response.model.<?php echo e($id); ?>,'/'));
                                <?php elseif(in_array($id,$model->getNumbers())): ?>
                                    $('#<?php echo e($id); ?>').val(formatNumber(response.model.<?php echo e($id); ?>));
                                <?php elseif(in_array($id,$model->getPasswords())): ?>
                                    $('#<?php echo e($id); ?>').val('');
                                <?php elseif(in_array($id,array_keys($model->getSelectsMultiple()))): ?>
                                    if(response.model.<?php echo e($id); ?>!=null){
                                        tab = response.model.<?php echo e($id); ?>.substr(1).split('~');
                                        $('#<?php echo e($id); ?>').val(tab);
                                        $('#<?php echo e($id); ?>').trigger('change');
                                     }
                                <?php elseif(in_array($id,$model->getImages())): ?>
                                    $('#<?php echo e($id); ?>').attr('data-default-file', sitehost+response.model.<?php echo e($id); ?>);
                                <?php elseif(in_array($id,$model->getTagInputs())): ?>
                                    $('#<?php echo e($id); ?>').tagsinput('removeAll');
                                    $('#<?php echo e($id); ?>').tagsinput('add', response.model.<?php echo e($id); ?>);
                                <?php else: ?>
                                    $('#<?php echo e($id); ?>').val(response.model.<?php echo e($id); ?>);
                                <?php endif; ?>
                            <?php endif; ?>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>


                        $('#modal-crud-form-opener').click();
                        $('.select2').each(function () {
                            $(this).select2({
                                dropdownParent: $(this).parent()
                            });
                        });
                    }else{
                        swal("Erreur!", "Error during operation.", "warning");
                    }
                });
                req.fail(function (jqXHR, textStatus) {
                    swal("Erreur!", "Error during operation.", "warning");
                });
            });
        });

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

<?php echo $__env->make('template', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\Users\UTILISATEUR\Desktop\Fidelisations\loyalty-system\loyalty-app\resources\views/inc/cruds/list.blade.php ENDPATH**/ ?>