<?php $__env->startSection('title', 'List matters'); ?>
<?php $__env->startSection('link'); ?>
<!-- Data Table Css -->
<link rel="stylesheet" href="<?php echo e(asset('bower_components/datatables.net-bs4/css/dataTables.bootstrap4.min.css')); ?>">
<link rel="stylesheet" href="<?php echo e(asset('assets/pages/data-table/css/buttons.dataTables.min.css')); ?>">
<link rel="stylesheet" href="<?php echo e(asset('bower_components/datatables.net-responsive-bs4/css/responsive.bootstrap4.min.css')); ?>">
<style>
    .dataTables_length label{
        display: none;
    }
</style>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('content'); ?>
<div class="pcoded-inner-content">
    <?php echo $__env->make('includes._alert', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
    <div class="main-body">
        <div class="page-wrapper">
            <div class="page-body">
                <div class="row">
                    <div class="col-sm-12">
                        <div class="card">
                            <div class="card-header">
                                <div class="d-flex justify-content-between">
                                    <h4>Gestion des disciplines</h4>
                                    <span class="divBtn" id="addBtn" style="display: none">
                                        <input type="hidden" value="" id="inputVal">
                                        <button class="btn btn-inverse btn-outline-inverse  btn-sm py-1" id="getLevel" data-toggle="modal" data-target="#matterModal" title="Ajout de discipline par niveau" style="display: none"><i class="far fa-edit mx-0"></i></button>
                                        <a href="#" class="btn btn-inverse btn-outline-inverse  btn-sm py-1" id="addNew" title="Ajout de discipline par type d'enseign..."> <i class="fas fa-plus mx-0"></i></a>
                                    </span>
                                </div>
                            </div>
                            <div class="card-block">
                                <div class="dt-responsive table-responsive">
                                    <ul class="nav nav-tabs md-tabs" role="tablist">
                                        <?php $__currentLoopData = $type; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <li class="nav-item" style="width: 18%">
                                            <a class="nav-link text-left <?php echo e(session('string') ? (session('string') == $item['libelle'] ? 'active':'' ):($item['nbre'] == 1 ? 'active':'')); ?> menuStep" id="<?php echo e(session('string') ? (session('string') == $item['libelle'] ? 'active':'' ):($item['nbre'] == 1 ? 'active':'')); ?>" data-nbre="<?php echo e(count($item['data'])); ?>" data-div="<?php echo e($item['libelle']); ?>" data-toggle="tab" href="#home<?php echo e($item['nbre']); ?>" role="tab" aria-selected="true">
                                                <i class="icofont icofont-home"></i><?php echo e(ucfirst($item['libelle'])); ?> [<?php echo e(count($item['data']) <= 9 ? '0'.count($item['data']):count($item['data'])); ?>]
                                            </a>
                                            <div class="slide" style="width: 16%"></div>
                                        </li>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </ul>
                                    
                                    <!-- Tab panes -->
                                    <div class="tab-content card-block">
                                        <?php $__currentLoopData = $type; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <div class="tab-pane <?php echo e(session('string') ? (session('string') == $item['libelle'] ? 'active':'' ):($item['nbre'] == 1 ? 'active':'')); ?>" id="home<?php echo e($item['nbre']); ?>" role="tabpanel">
                                            <table id="<?php echo e($item['tab']); ?>" class="table table-striped table-bordered nowrap">
                                                <thead>
                                                    <tr>
                                                        <th class="text-center">N°</th>
                                                        <th>Libelle</th>
                                                        <th>Abréviation</th>
                                                        <th class="text-center">Actions</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <?php $i = 1; ?>
                                                    <?php $__currentLoopData = $item['data']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $val): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <tr>
                                                        <th class="text-center"><?php echo e($i <= 9 ? '0'.$i++:$i++); ?></th>
                                                        <td><?php echo e(ucfirst($val->libelle)); ?></td>
                                                        <td><?php echo e($val->abbreviated ?? '---'); ?></td>
                                                        <td class="py-1">
                                                            <div class="card-block remove-label m-0 p-0 text-center">
                                                                <button class="getEdit btn btn-sm btn-info text-center px-2" data-div="<?php echo e($val->matter_id); ?>" data-toggle="modal" data-target="#exampleModal"itle="Edité cette discipline"><i class="far fa-edit mx-0"></i></button>
                                                                <button class="getDelet btn btn-sm btn-danger text-white text-center px-2 mx-2" title="Désactivé" data-lib="<?php echo e($item['libelle']); ?>" data-div="<?php echo e($val->id.'_'.ucfirst($val->libelle)); ?>" data-toggle="modal" data-target="#exampleModalCenter"><i class="far fa-trash-alt mx-0"></i></button>
                                                            </div>
                                                        </td>
                                                    </tr>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                </tbody>
                                            </table>
                                        </div>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </div> 
                                </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content">
            <div class="modal-header bg-danger py-2">
                <h5 class="modal-title" id="exampleModalLongTitle">Confirmation</h5>
            </div>
            <div class="modal-body">
            <div class="row">
                <div class="col-12 text-center">
                    <p id="addVal"></p>
                    <p class="my-0">
                        <strong>Vous êtes sur de désactiver cette discipline.</strong>
                    </p>
                    <span>Cliquez sur le 'Confirmer' pour achéver l'action.</span>
                </div>
            </div>
            </div>
            <form action="<?php echo e(route('matiere.update')); ?>" method="post" id="myForm">
                <?php echo csrf_field(); ?>
                <?php echo method_field('get'); ?>
                <input type="hidden" name="matter" id="matterId">
                <input type="hidden" name="libelle" id="libVal">
                <div class="modal-footer">
                    <button type="button" class="btn btn-inverse btn-outline-inverse btn-sm py-1 mx-2" data-dismiss="modal">Annuler</button>
                    <button type="submit" class="btn btn-inverse btn-outline-inverse btn-sm py-1 mx-2">Confirmer</button>
                </div>
            </form>
        </div>
    </div>
</div>


<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <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" id="exampleModalLabel">Edit discipline</h5>
        </div>
        <form method="post" id="myEdit">
            <?php echo method_field('put'); ?>
            <?php echo csrf_field(); ?>
            <div class="modal-body">
                <div class="form-group">
                    <label for="name" class="col-form-label">Nom de la matière<span class="text-danger">*</span> :</label>
                    <input type="text" name="name" class="form-control" id="name" placeholder="Entrez le nom de la matière">
                </div>
                <div class="form-group">
                    <label for="abrege" class="col-form-label"for="abrege">Nom abrégé de la matière :</label>
                    <input type="text" name="abrege" id="abrege" class="form-control" placeholder="Entrez le nom abrégé de la matière">
                </div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-inverse btn-outline-inverse btn-sm py-1 mx-2" data-dismiss="modal">Annuler</button>
                <button type="submit" class="btn btn-inverse btn-outline-inverse btn-sm py-1 mx-2">Confirmer</button>
            </div>
        </form>
      </div>
    </div>
</div>


<div class="modal fade" id="matterModal" tabindex="-1" role="dialog" aria-labelledby="matterModalLabel" aria-hidden="true">
    <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" id="matterModalLabel">Gestion des matières</h5>
        </div>
        <form method="post" id="myLevel">
            <?php echo csrf_field(); ?>
            <div class="modal-body">
                <div class="form-group mb-3">
                    <label for="mySelect" class="col-form-label">Selectioner une option<span class="text-danger">*</span> :</label>
                    <select name="level" id="mySelect" class="form-control">
                        <option value="">Select one level ...</option>
                    </select>
                </div>
                <div class="form-group mb-3" style="display: none" id="divSerie">
                    <label for="SelectSerie" class="col-form-label">Veuillez selectionner<span class="text-danger">*</span> :</label>
                    <select name="serie" id="SelectSerie" class="form-control">
                        <option value="">Select one level ...</option>
                    </select>
                </div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-inverse btn-outline-inverse btn-sm py-1 mx-2" data-dismiss="modal">Annuler</button>
                <button type="submit" class="btn btn-inverse btn-outline-inverse btn-sm py-1 mx-2">Confirmer</button>
            </div>
        </form>
      </div>
    </div>
</div>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('script'); ?>
    <!-- data-table js -->
    <script src="<?php echo e(asset('bower_components/datatables.net/js/jquery.dataTables.min.js')); ?>"></script>
    <script src="<?php echo e(asset('bower_components/datatables.net-buttons/js/dataTables.buttons.min.js')); ?>"></script>
    <script src="<?php echo e(asset('assets/pages/data-table/extensions/autofill/js/dataTables.autoFill.min.js')); ?>"></script>
    <script src="<?php echo e(asset('bower_components/datatables.net-buttons/js/buttons.print.min.js')); ?>"></script>
    <script src="<?php echo e(asset('bower_components/datatables.net-buttons/js/buttons.html5.min.js')); ?>"></script>
    <script src="<?php echo e(asset('assets/pages/data-table/js/dataTables.bootstrap4.min.js')); ?>"></script>
    <script src="<?php echo e(asset('bower_components/datatables.net-responsive/js/dataTables.responsive.min.js')); ?>"></script>
    <script src="<?php echo e(asset('bower_components/datatables.net-responsive-bs4/js/responsive.bootstrap4.min.js')); ?>"></script>
    <!-- Custom js -->
    <script src="<?php echo e(asset('assets/pages/data-table/extensions/colreorder/js/colreorder-custom.js')); ?>"></script>
    <script src="<?php echo e(asset('assets/js/pcoded.min.js')); ?>"></script>
    <script src="<?php echo e(asset('assets/js/vartical-layout.min.js')); ?>"></script>
    <script src="<?php echo e(asset('assets/js/jquery.mCustomScrollbar.concat.min.js')); ?>"></script>
    <script>
        $(document).ready(function(){
            var currentUrl = window.location.href;
            let debutUrl = currentUrl.split("matter");
            let val = $('#active').data('div');
            $('#addNew').attr('href', debutUrl[0]+'matter/create/'+val);
            $('#inputVal').val(val);
            let nbre = $('#active').data('nbre');
            nbre == 0 ? $('#getLevel').hide():$('#getLevel').show();
            if(val == 'Prescolaire - Primaire' || val == 'Primaire' ||  val == 'Prescolaire'){
                $('.divBtn').slideUp()
            }
            else{
                $('.divBtn').slideDown()
            }


            // $val = "<?php echo e(route('matiere.create',"+val+")); ?>";
            $('.menuStep').on('click', function(){
                let val = $(this).data('div');
                $('#addNew').attr('href', debutUrl[0]+'matter/create/'+val);
                $('#inputVal').val(val);
                let nbre = $(this).data('nbre');
                nbre == 0 ? $('#getLevel').hide():$('#getLevel').show();
            });


            $(document).on('click', '.getEdit', function(e) {
                e.preventDefault();
                var div = $(this).data('div');
                $('#myEdit').attr('action', debutUrl[0]+'matter/matter/'+div); // Add action form Modal
                $.ajax({
                    url: '<?php echo e(route('matiere.search')); ?>', // La route définie dans web.php
                    method: 'GET',
                    data: { data: div },
                    success: function(response){
                        $('div#exampleModal').fadeIn();
                        $('#name').val(response['libelle']);
                        $('#abrege').val(response['abbreviated']);
                    }
                });
            });

            // Delete user ................................ 
            $(document).on('click', '.getDelet', function(e) {
                e.preventDefault();
                $('#modalUser').remove();
                var div = $(this).data('div'); 
                var val = div.split("_");
                $('#libVal').val($(this).data('lib'));
                $('#matterId').val(val[0]);
                $('#addVal').append('<h5 class="mb-1 mt-2" id="modalUser">'+val[1]+'</h4>');
            });


            $('#getLevel').click(function(e){
                e.preventDefault();
                $('.itemSelect').remove();
                var div = $("#inputVal").val();
                $('#myLevel').attr('action', debutUrl[0]+'matter/getMatter/'+div); // Add action form Modal
                $.ajax({
                    url: '<?php echo e(route('getMatter.search')); ?>', // La route définie dans web.php
                    method: 'GET',
                    data: {
                        data: div
                    },
                    success: function(data){
                        $('div#matterModal').fadeIn();
                        let i = 0; 
                        while (i < data.length) {
                            var text = data[i].level;
                            var capitalizedText = text.charAt(0).toUpperCase() + text.slice(1);
                            $('#mySelect').append('<option value="'+data[i].id+'" class="itemSelect">'+capitalizedText+'</option>');
                            i++;
                        }
                    }
                });
            });

            $('#mySelect').on('change', function() {
                $('.itemSerie').remove();
                $.ajax({
                    url: '<?php echo e(route('getMatter.serie')); ?>', // La route définie dans web.php
                    method: 'GET',
                    data: {
                        level: $(this).val(),
                        string: $("#inputVal").val()
                    },
                    success: function(data){
                        if(!(data == 201)){
                            $('#divSerie').slideDown();
                            let i = 0; 
                            while (i < data.length) {
                                $('#SelectSerie').append('<option value="'+data[i].id+'" class="itemSerie">'+data[i].serie+'</option>');
                                i++;
                            }
                        }
                        else{
                            $('#divSerie').slideUp();
                        }
                    }
                });
            });

            $('.nav-link').on('click', function() {
                $actif = $(this).data('div');
                if($actif == 'Prescolaire - Primaire' || $actif == 'Primaire' ||  $actif == 'Prescolaire'){
                    $('.divBtn').slideUp()
                }
                else{
                    $('.divBtn').slideDown()
                }
            });
        })
    </script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\Users\EDUCAS\Desktop\AppS\V4_001\resources\views\pages\matters\index.blade.php ENDPATH**/ ?>