<?php $__env->startSection('intitule'); ?>
    <h5 class="font-weight-medium text-uppercase mb-0">INSERTION DES NOTES PAR ELEMENT CONSTITUTIF : SESSION DE RATTRAPAGE
    </h5>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('breadcrumb'); ?>
    <li class="breadcrumb-item active" aria-current="page">Insertion notes</li>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('styles'); ?>
    <link href="<?php echo e(asset('assets/extra-libs/toastr/dist/build/toastr.min.css')); ?>" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="<?php echo e(asset('assets/libs/select2/dist/css/select2.min.css')); ?>">
<?php $__env->stopSection(); ?>

<?php $__env->startSection('main'); ?>
    <div class="row justify-content-center mt-4" style="min-height: calc(85vh - 60px)">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-header p-4" style="background-color:<?php echo e(Session::get('RESULTAT_DATA')['RESULTAT_COULEUR_ETAB1']); ?> ">
                    <h4 class="mb-0" style="color:<?php echo e(Session::get('RESULTAT_DATA')['RESULTAT_COULEUR_TEXT1']); ?> ">Veuillez sélectionner les données s'il vous plait.</h4>
                </div>
                <div class="card-body">
                    <form class="form-horizontal" method="POST" action="<?php echo e(route('insertion.rattrapage.list')); ?>"
                        id="submit">
                        <?php echo csrf_field(); ?>
                        <div class="mb-3 pb-3 row border-bottom align-items-center">
                            <label for="" class="control-label text-md-end col-md-3">Plafonner</label>
                            <div class="col-md-6">
                                <select class="form-select mr-sm-2 p-2" id="YesNo" name="plafond">
                                    <option value="0">NO : La note de l'UE n'est pas plafonnée à la note requise en cas
                                        de validation</option>
                                    <option value="1">YES : La note de l'UE est plafonnée à la note requise en cas de
                                        validation</option>
                                </select>
                            </div>
                        </div>

                        <div class="mb-3 pb-3 row border-bottom align-items-center">
                            <label for="" class="control-label text-md-end col-md-3">Filière</label>
                            <div class="col-md-6">
                                <select class="select2 p-2" style="width: 100%" id="filiere" name="idFiliere">
                                    <option>Selectionner la filière</option>
                                    <?php $__currentLoopData = $data['filieres']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $filiere): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($filiere->idFiliere); ?>">
                                            <?php echo e($filiere->intituleFilieres); ?>(<?php echo e($filiere->sigleFilieres); ?>)</option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                                <div class="invalid-feedback">
                                    La filière est requise
                                </div>
                            </div>
                        </div>
                        <div class="mb-3 pb-3 row border-bottom align-items-center">
                            <label for="" class="control-label text-md-end col-md-3">Année Académique</label>
                            <div class="col-md-6">
                                <select class="form-select mr-sm-2 p-2" id="acadYear" name="acadYear">
                                    <option value="<?php echo e(Session::get('RESULTAT_DATA')['RESULTAT_YEAR']->annee_acad); ?>">
                                        <?php echo e(Session::get('RESULTAT_DATA')['RESULTAT_YEAR']->periode); ?></option>
                                </select>
                            </div>
                        </div>
                        <div class="mb-3 pb-3 row border-bottom align-items-center">
                            <label for="" class="control-label text-md-end col-md-3">Niveau formation</label>
                            <div class="col-md-6">
                                <select class="form-select mr-sm-2 p-2" id="formation" name="formation">
                                    <?php $__currentLoopData = $data['formations']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $formation): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($formation->id); ?>"><?php echo e($formation->niveauFormation); ?></option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                            </div>
                        </div>
                        <div class="mb-3 pb-3 row border-bottom align-items-center">
                            <label for="" class="control-label text-md-end col-md-3">Année d'Etude</label>
                            <div class="col-md-6">
                                <select class="form-select mr-sm-2 p-2" id="etudeYear" name="etudeYear">
                                    <option>Sélectionner l'année d'étude</option>
                                    <?php $__currentLoopData = $data['etudes']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $etude): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($etude->id); ?>"><?php echo e($etude->annee_etude); ?></option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                                <div class="invalid-feedback">
                                    L'année d'étude est requise
                                </div>
                            </div>
                        </div>
                        <div class="mb-3 pb-3 row border-bottom align-items-center">
                            <label for="" class="control-label text-md-end col-md-3">Choisir une UE</label>
                            <div class="col-md-6">
                                <select class="select2 p-2 select2-data-array" style="width: 100%" id="ue"
                                    name="ue">

                                </select>
                                <div class="invalid-feedback">
                                    L'UE est requise
                                </div>
                            </div>
                        </div>
                        <div class="form-actions">
                            <div class="row">
                                <div class="col-md-12">
                                    <div class="row justify-content-center">

                                        <button type="submit" class="col-3 col-md-1 col-sm-2 me-3 btn btn-success"> <i
                                                class="fa fa-check"></i> Submit</button>
                                        <button type="reset" class="col-4 col-md-2 col-sm-3 col-lg-1 me-3 btn "
                                            style="background-color: #e4e7ea">Cancel</button>

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

<?php $__env->startSection('scripts'); ?>
    <script src="<?php echo e(asset('assets/libs/select2/dist/js/select2.full.min.js')); ?>"></script>
    <script src="<?php echo e(asset('assets/libs/select2/dist/js/select2.min.js')); ?>"></script>
    <script src="<?php echo e(asset('dist/js/pages/forms/select2/select2.init.js')); ?>"></script>
    <script src="<?php echo e(asset('assets/extra-libs/toastr/dist/build/toastr.min.js')); ?>"></script>
    <script src="<?php echo e(asset('assets/extra-libs/toastr/toastr-init.js')); ?>"></script>
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.4.29/dist/sweetalert2.all.min.js"></script>
    <script>
        $(() => {
            let request = async () => {
                if (!(isNaN($("#filiere").val()) || isNaN($("#acadYear").val()) || isNaN($(
                            "#formation").val()) ||
                        isNaN($("#etudeYear").val()))) {
                    let url = "<?php echo e(route('ue')); ?>";
                    let token = document
                        .querySelector('meta[name="csrf-token"]')
                        .getAttribute("content");

                    let options = {
                        headers: {
                            "Content-Type": "application/json",
                            Accept: "application/json, text-plain, */*",
                            "X-Requested-With": "XMLHttpRequest",
                            "X-CSRF-TOKEN": token,
                        },
                        method: "post",
                        credentials: "same-origin",
                        body: JSON.stringify({
                            idFiliere: $("#filiere").val(),
                            acad_year: $("#acadYear").val(),
                            formation: $("#formation").val(),
                            etude_year: $("#etudeYear").val()
                        }),
                    };
                    await fetch(url, options)
                        .then((response) => response.json())
                        .then((response) => {
                            if (response.success) {
                                let data = response.data;
                                if (data.length) {
                                    let selectData = [];
                                    for (let semestre in data.ues) {
                                        let ues = [];
                                        for (let ue in data.ues[semestre]) {
                                            ues.push({
                                                id: ue,
                                                text: data.ues[semestre][ue]
                                            });
                                        }
                                        selectData.push({
                                            text: '============================== Semestre ' +
                                                semestre +
                                                ' ==============================',
                                            children: ues
                                        });
                                    }
                                    $(".select2-data-array").select2("destroy");
                                    $(".select2-data-array").select2({
                                        placeholder: "Choisir un élément constitutif",
                                        pagination: {
                                            "more": true
                                        },
                                        data: selectData
                                    });
                                } else
                                    toaster("warning", "Pas d'EC pour les données saisies.");
                            } else
                                toaster("warning",
                                    "Erreur de connection, veuillez recharger la page.");
                        })
                        .catch((e) => {
                            console.log(e)
                            toaster("error",
                                "Une erreur est survenue, veuillez recharger la page.");
                        });
                }
            };
            $('#filiere').change(request);
            $('#acadYear').change(request);
            $('#formation').change(request);
            $('#etudeYear').change(request);
            $(".select2-data-array").select2({
                placeholder: "Choisir un élément constitutif",
                language: {
                    noResults: () => "Traitement tableau de spécification en cours..."
                }
            });
            $('#submit').submit((e) => {
                if (![checkValidation('#YesNo'),
                        checkValidation('#filiere'),
                        checkValidation('#acadYear'),
                        checkValidation('#formation'),
                        checkValidation('#etudeYear'),
                        checkValidation('#ue')
                    ].every(value => value === true)) {
                    e.preventDefault();
                }
            });
            <?php if(Session::get('noData')): ?>
                let title = '<p>Aucun étudiant n\'est inscrit dans la filière : <span style="color:red">';
                title += "<?php echo e(Session::get('intituleFilieres')); ?>";
                title +=
                    '</span> </p> <p>Ou</p> <p>Vous ne pouvez pas continuer une une insertion de notes de rattrapage pour: <span style="color:red">';
                title += "<?php echo e(Session::get('intituleUE')); ?>";
                title += '</span>. Certainement tous les étudiants ont validés cette UE';
                title += "</p>";
                Swal.fire({
                    icon: 'error',
                    title: 'Oops...',
                    html: title
                });
            <?php endif; ?>
        });
    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.template', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/africawebstudent/public_html/aws/insertue/resources/views/sessions/formrattrapage.blade.php ENDPATH**/ ?>