<?php $__env->startSection('Activite'); ?>
    <style>
        .bg-cronos {
            background-color: #0b440e;
        }

        .btn-cronos {
            background-color: #0b440e;
            color: #ffff;
        }
    </style>
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">

                </div>
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-right">
                        <?php echo $__env->make('sweetalert::alert', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                    </ol>
                </div>
            </div>
        </div><!-- /.container-fluid -->
    </section>


    <!-- Main content -->
    <section class="content">
        <div class="container-fluid">
            <!-- SELECT2 EXAMPLE -->
            <div class="card ">
                <div class="card-header bg-cronos">
                    <h2 class="card-title text-white">Gestion des Offres d'emploie</h2>
                    <div class="card-tools">
                    </div>
                </div>
                <!-- /.card-header -->
                <div class="card-body">
                    <a id="btnModalFormGestionOffre" href="#modalFormGestionOffre" class="btn btn-cronos text-white add"
                        data-toggle="modal" data-backdrop="static" data-keyboard="false"><i class="fas fa-plus-circle"></i>
                        <span>Ajouter un Offre</span></a>

                    <table class="table table-striped table-bordered table-hover" data-toolbar="#btnModalFormGestionStation"
                        id="table" data-toggle="table" data-search="true" data-pagination="true" data-ajax="ajaxRequest"
                        data-buttons-class="cronos" data-show-refresh="true" data-show-toggle="true"
                        data-show-footer="false" data-footer-style="footerStyle" data-show-fullscreen="true"
                        data-show-columns="true" data-show-columns-toggle-all="true" data-show-export="true"
                        data-detail-view="true" data-detail-formatter="detailFormatter" data-click-to-select="true"
                        data-select-item-name="toolbar" data-sort-name="name" data-page-size="10" data-sort-order="desc"
                        data-export-types="['csv','excel','pdf']">

                        <thead>
                            <tr>
                                <th data-field="titreOffre" data-sortable="true">Titre Offre</th>
                                <th data-field="datePermission" data-sortable="true">Date Permission</th>
                                <th data-field="nomEmployeur" data-sortable="true">Nom Employeur</th>
                                <th data-formatter="actionFormatter" data-events="actionEvents">Action</th>
                            </tr>
                        </thead>
                    </table>
                </div>
                <!-- /.card-body -->
                <div class="card-footer"></div>
            </div>
            <!-- /.card -->

        </div><!-- /.container-fluid -->
    </section>
    <!-- /.content -->
    <?php echo $__env->make('Admin.pages.File_Offre.addOffre', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
    <?php echo $__env->make('Admin.pages.File_Offre.deleteOffre', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
    <?php echo $__env->make('Admin.pages.File_Offre.editOffre', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
    <?php echo $__env->make('Admin.pages.File_Offre.addQuestion', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
    <?php echo $__env->make('Admin.pages.File_Offre.editQuestion', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
    <?php echo $__env->make('Admin.pages.File_Offre.viewQuestion', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
    <!-- Modal-->
<?php $__env->stopSection(); ?>

<?php $__env->startSection('script'); ?>
    <script>
        function actionFormatter(value, row, index) {
            return [
                '<a class="editGestionOffre" style="color:#2f4f4f" href="javascript:void(0)" title="Modifier">',
                '<i class="fas fa-edit" aria-hidden="true"></i>',
                '</a>',
                '&nbsp;&nbsp;',
                '<a class="deleteGestionOffre" style="color:red" href="javascript:void(0)" title="Supprimer">',
                '<i class="fas fa-trash" aria-hidden="true"></i>',
                '</a>',
                '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
                '<a class="addQuestion" style="color:green" href="javascript:void(0)" title="Ajouter une question">',
                '<i class="fas fa-question-circle" aria-hidden="true"></i>',
                '</a>',
                '&nbsp;&nbsp;',
                '<a class="vueQuestion" style="color:green" href="javascript:void(0)" title="Ajouter une question">',
                '<i class="fas fa-eye" aria-hidden="true"></i>',
                '</a>',
                '&nbsp;&nbsp;',
                '<a class="editQuestion" style="color:green" href="javascript:void(0)" title="Modifier">',
                '<i class="fas fa-pencil-alt" aria-hidden="true"></i>',
                '</a>',
            ].join('');
        }

        window.actionEvents = {
            'click .editGestionOffre': function(e, value, row, index) {
                var id = row.id;
                $('#ModalEdit').modal('show');
                $.ajax({
                    type: "GET",
                    url: "<?php echo e(route('gestionOffre.edit', ['id' => ':id'])); ?>".replace(':id', id),
                    success: function(response) {
                        $('#titreOffres').val(response.Offres.titreOffre);
                        $('#datePermissions').val(response.Offres.datePermission);
                        $('#idEmployeurs').val(response.Offres.idEmployeur);
                        $('#descriptionOffres').summernote("code", response.Offres.descriptionOffre);
                        $('#ids').val(response.Offres.id);
                    }
                });
            },


            'click .deleteGestionOffre': function(e, value, row, index) {
                var id = row.id;
                $('#ModalDelete').modal('show');
                $('#deleteing_id').val(id);
            },

            'click .addQuestion': function(e, value, row, index) {
                var id = row.id
                $('#ModalQuestion').modal('show');
                $.ajax({
                    type: "GET",
                    url: "<?php echo e(route('gestionOffre.edit', ['id' => ':id'])); ?>".replace(':id', id),
                    success: function(response) {
                        console.log(response);
                        $('#idQuestions').val(response.Offres.id);
                    }
                });
            },
            'click .vueQuestion': function(e, value, row, index) {
                var id = row.id;
                $('#viewQuestion').modal('show');

                // Réinitialisez le contenu de la liste déroulante
                $('#Question').html('<option selected>Chargement en cours...</option>');

                $.ajax({
                    url: '/View+question',
                    type: 'POST',
                    data: {
                        selectedValue: id
                    },
                    dataType: 'json',
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    },
                    // ...

                    success: function(response) {
                        console.log(response);

                        // Assurez-vous que le modal est bien affiché
                        $('#viewQuestion').modal('show');

                        // Obtenez la référence de la div container dans le modal
                        var container = $('#viewQuestion').find('.container');

                        // Effacez le contenu existant
                        container.empty();

                        // Ajoutez les nouvelles données au contenu du modal
                        $.each(response, function(index, question) {
                            // Créez des éléments HTML pour chaque question et ses réponses
                            var questionDiv = $('<div class="question">');
                            questionDiv.append('<h5>' + question.question + '</h5>');

                            // Ajoutez les réponses
                            var reponsesDiv = $('<div class="reponses">');
                            $.each(question, function(key, value) {
                                if (key.startsWith('reponse')) {
                                    reponsesDiv.append('<p>- ' + value + '</p>');
                                }
                            });

                            // Ajoutez les points
                            var pointsDiv = $('<div class="points">');
                            $.each(question, function(key, value) {
                                if (key.startsWith('point')) {
                                    pointsDiv.append('<p>- ' + value + '</p>');
                                }
                            });

                            questionDiv.append(reponsesDiv);
                            questionDiv.append(pointsDiv);
                            container.append(questionDiv);
                        });
                    }
                });
            },
            'click .editQuestion': function(e, value, row, index) {
                var id = row.id;
                $('#EditQuestion').modal('show');

                // Réinitialisez le contenu de la liste déroulante
                $('#Question').html('<option selected>Chargement en cours...</option>');

                $.ajax({
                    url: '/Modification+question',
                    type: 'POST',
                    data: {
                        selectedValue: id
                    },
                    dataType: 'json',
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    },
                    success: function(response) {
                        console.log(response);

                        // Mettez à jour les options de la liste déroulante
                        var $select = $('#Question');
                        $select.empty();
                        $select.append('<option selected>Choisir une question</option>');

                        // Ajoutez les options depuis la réponse de la requête Ajax
                        $.each(response, function(index, question) {
                            $select.append('<option value="' + question.id + '">' + question
                                .question + '</option>');
                        });
                    }
                });
            },
        };

        function detailFormatter(index, row) {
            var html = []

            html.push('<p><b>Description  : </b> ' + row.descriptionOffre + '</p>')


            return html.join('');
        }
    </script>

    <script>
        // your custom ajax request here
        function ajaxRequest(params) {
            var url = '<?php echo e(route('Gestion+Offre.create')); ?>'
            $.get(url + '?' + $.param(params.data)).then(function(res) {
                params.success(res)
            })
        }
    </script>

    <script>
        $(function() {
            // Summernote
            $('#summer').summernote({
                height: 100,
                placeholder: 'Entrer un texte',
            });

            // CodeMirror
            CodeMirror.fromTextArea(document.getElementById("codeMirrorDemo"), {
                mode: "htmlmixed",
                theme: "monokai"
            });
        })
    </script>

    <script>
        // Ajoutez un gestionnaire d'événements au changement de sélection de la question
        $('#Question').change(function() {
            var selectedQuestionId = $(this).val();

            // Effectuez une requête Ajax pour récupérer les réponses liées à la question sélectionnée
            $.ajax({
                url: '/recupererReponses',
                type: 'POST',
                data: {
                    selectedQuestionId: selectedQuestionId
                },
                dataType: 'json',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                success: function(response) {
                    // Mettez à jour les champs de réponse avec les données de la réponse
                    $('#questionA').val(response.question);
                    $('#reponse12').val(response.reponse1);
                    $('#point13').val(response.point1);
                    $('#reponse24').val(response.reponse2);
                    $('#point25').val(response.point2);
                    $('#reponse36').val(response.reponse3);
                    $('#point37').val(response.point3);
                    $('#reponse48').val(response.reponse4);
                    $('#point49').val(response.point4);
                    $('#reponse50').val(response.reponse5);
                    $('#point51').val(response.point5);
                    $('#id1').val(response.id);
                }
            });
        });
    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('Admin.pages.layout.header', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\Users\El Anewar\Downloads\Takaback\resources\views/Admin/pages/File_Offre/Offre.blade.php ENDPATH**/ ?>