@extends('layouts.base')

@section('title', 'Starter Page')

@section('css')
    {{-- include page's specific styles here  --}}
    <link href="{{ asset('assets/extra-libs/datatables.net-bs4/css/dataTables.bootstrap4.css') }}" rel="stylesheet">
    <link rel="stylesheet" type="text/css"
        href="{{ asset('assets/extra-libs/datatables.net-bs4/css/responsive.dataTables.min.css') }}">
@endsection

@section('content')
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="border-bottom title-part-padding">
                    <h4 class="card-title mb-0">DATA export</h4>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table id="file_export" class="table table-striped table-bordered display text-center">
                            <thead>
                                <tr>
                                    <th>#</th>
                                    <th>Photo</th>
                                    <th>Matricule</th>
                                    <th>Nom</th>
                                    <th>Prénom</th>
                                    <th>Date Naissance</th>
                                    <th>Lieu Naissance</th>
                                    <th>Statut</th>
                                    <th>Filiere</th>
                                    <th>Sexe</th>
                                    <th>Nationalité</th>
                                    <th>Niveau</th>
                                    <th class="js-not-exportable">Afficher Dossier</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                $idEtablissement = App\Models\EtablissementInfo::first()->idEtablissement;
                                ?>
                                @foreach ($data['studentsData'] as $student)
                                    <tr>
                                        @php
                                            $statut = App\Models\Statuts::whereRaw('idStatut = :id AND idEtablissement = :idEtablissement', ['id' => $student->statut, 'idEtablissement' => $idEtablissement])->first();

                                            if ($student->niveauFormation == 1) {
                                                $niveau = 'Licence';
                                            } elseif ($student->niveauFormation == 2) {
                                                $niveau = 'Master';
                                            } else {
                                                $niveau = 'Doctorat';
                                            }

                                            $filiere = App\Models\Filieres::where('idFiliere', $student->idFiliere)->first();

                                            if ($student->cheminPhoto == '') {
                                                $student->cheminPhoto = 'imageEtudiant/votrephoto.jpg';
                                            }
                                        @endphp
                                        <td align=center>{{ $student->idDossier }}</td>
                                        <td><img src="../Inscription/{{ $student->cheminPhoto }}" alt=""
                                                height="60" width="60"></td>
                                        <td>{{ $student->matricule }}</td>
                                        <td>{{ $student->nom }}</td>
                                        <td>{{ $student->prenom }}</td>
                                        <td>{{ $student->date_nais }}</td>
                                        <td>{{ $student->lieu_nais }}</td>
                                        <td>{{ $statut->statut }}</td>
                                        <td>{{ $filiere->sigleFilieres . $student->annee }}</td>
                                        <td>{{ $student->sexe }}</td>
                                        <td>{{ $student->nationalite }}</td>
                                        <td>{{ $niveau }}</td>
                                        <td align=center class="js-not-exportable">
                                            <a href="{{ route('page_dossier', [
                                                'matricule' => $student->matricule,
                                                'annee' => $student->annee,
                                                'idFiliere' => $student->idFiliere,
                                                'fil' => $filiere->sigleFilieres,
                                                'niv' => $student->niveauFormation,
                                                'name' => $student->nom . ' ' . $student->prenom,
                                            ]) }}"
                                                target="_blank">
                                                <button type="button"
                                                    class="btn btn-info btn-outline btn-circle btn-lg m-r-5 modifier"
                                                    data-toggle="modal" data-target="#update-domiane"><i
                                                        class="mdi mdi-eye"></i>
                                                </button>
                                            </a>
                                    </tr>
                                @endforeach
                            </tbody>
                            <tfoot>
                                <tr>
                                    <th>#</th>
                                    <th>Photo</th>
                                    <th>Matricule</th>
                                    <th>Nom</th>
                                    <th>Prénom</th>
                                    <th>Date Naissance</th>
                                    <th>Lieu Naissance</th>
                                    <th>Statut</th>
                                    <th>Filiere</th>
                                    <th>Sexe</th>
                                    <th>Nationalité</th>
                                    <th>Niveau</th>
                                    <th>Afficher Dossier</th>
                                </tr>
                            </tfoot>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('script')
    {{-- include page's specific scripts here --}}
    <script src="{{ asset('assets/extra-libs/datatables.net/js/jquery.dataTables.min.js') }}"></script>
    <script src="{{ asset('assets/extra-libs/datatables.net-bs4/js/dataTables.responsive.min.js') }}"></script>
    <script src="{{ asset('dist/js/pages/datatable/datatable-basic.init.js') }}"></script>
    <script src="https://cdn.datatables.net/buttons/1.5.1/js/dataTables.buttons.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.5.1/js/buttons.flash.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/pdfmake.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/vfs_fonts.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.5.1/js/buttons.html5.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.5.1/js/buttons.print.min.js"></script>
    <script src="{{ asset('dist/js/pages/datatable/datatable-advanced.init.js') }}"></script>
    <script>
        $(function() {
            $(".modifier").on('click', function() {
                var ele = $(this).parent();
                //Remplir le modal avant de l'afficher
                let matricule = ele.siblings(".matricule").val().trim();
                let nom = ele.siblings(".nom").val().trim();
                let prenom = ele.siblings(".prenom").val().trim();
                let date_nais = ele.siblings(".date_nais").val().trim();
                let lieu_nais = ele.siblings(".lieu_nais").val().trim();
                let statut = ele.siblings(".statut").val().trim();
                let nation = ele.siblings(".nationalite").val().trim();
                let idFiliere = ele.siblings(".idFiliere").val().trim();
                let sexe = ele.siblings(".sexe").val().trim();
                let imageUpload = ele.siblings(".imageUpload").val().trim();

                console.log(matricule);

                $("#frm_edit #show_matricule").val(matricule);
                $("#frm_edit #show_nom").val(nom);
                $("#frm_edit #show_prenom").val(prenom);
                $("#frm_edit #show_date").val(date_nais);
                $("#frm_edit #show_lieu").val(lieu_nais);
                $("#frm_edit #show_statut").val(statut);
                $("#frm_edit #show_idFiliere").val(idFiliere);
                $("#frm_edit #show_nation").val(nation);
                $("#frm_edit #show_sexe").val(sexe);
                $("#frm_edit #show_imageUpload").val(imageUpload);

                $("#edit_model").modal('show');
            });

            $("#btn_edit").on('click', function() {
                //console.log("matricule");

                if ($('#show_imageUpload').val() == '') {
                    swal({
                        title: "",
                        text: "Bien vouloir choisir une image",
                        type: "error",
                        closeOnConfirm: false,
                        showLoaderOnConfirm: true,
                        confirmButtonClass: "btn-danger",
                        confirmButtonText: "OK",
                        confirmButtonColor: "#ec6c62"
                    });
                } else {
                    $.post(
                        'updatephoto.php', {
                            matricule: $('#show_matricule').val(),
                            imageUpload: $('#show_imageUpload').val(),
                        },
                        function(data) {
                            $('#edit_model .modal-content').html(data);
                        },
                        'html'
                    );

                }

            });
        })
    </script>
@endsection
