@extends('layout.template')
@section('intitule')
    <h5 class="font-weight-medium text-uppercase mb-0">STATISTIQUES DE VALIDATION DES UES</h5>
@endsection

@section('breadcrumb')
    <li class="breadcrumb-item active" aria-current="page">Statistiques</li>
@endsection

@section('styles')
@endsection

@section('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: {{ Session::get('RESULTAT_DATA')['RESULTAT_COULEUR_ETAB1'] }}; color: {{ Session::get('RESULTAT_DATA')['RESULTAT_COULEUR_TEXT1'] }};">
                    <h4 class="mb-0 text-white">Veuillez sélectionner les données s'il vous plait.</h4>
                </div>
                <div class="card-body">
                    <form method="POST" class="form-horizontal" id="submit" action="{{ route('ficheConseilPdf') }}"
                        target="_blank">
                        @csrf
                        <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="{{ Session::get('RESULTAT_DATA')['RESULTAT_YEAR']->annee_acad }}">
                                        {{ 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">
                                    @foreach ($data['formations'] as $formation)
                                        <option value="{{ $formation->id }}">{{ $formation->niveauFormation }}</option>
                                    @endforeach
                                </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>
                                    @foreach ($data['etudes'] as $etude)
                                        <option value="{{ $etude->id }}">{{ $etude->annee_etude }}</option>
                                    @endforeach
                                </select>
                                <div class="invalid-feedback">
                                    L'année d'étude 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="button" id="swal"
                                            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>
@endsection

@section('scripts')
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.4.29/dist/sweetalert2.all.min.js"></script>

    <script>
        // $(()=>{
        //     $('#submit').submit((e) => {
        //             if (![
        //                     checkValidation('#acadYear'),
        //                     checkValidation('#formation'),
        //                     checkValidation('#etudeYear')

        //                 ].every(value => value === true)) {
        //                 e.preventDefault();
        //             }
        //         });
        //   })
    </script>
    <script>
        $('#swal').click((e) => {
            if (![
                    checkValidation('#acadYear'),
                    checkValidation('#formation'),
                    checkValidation('#etudeYear')

                ].every(value => value === true)) {
                e.preventDefault();
            } else {
                Swal.fire({
                    title: '',
                    text: "Voulez vous générer le PDF ?",
                    icon: 'question',
                    showCancelButton: true,
                    cancelButtonColor: '#595959',
                    confirmButtonColor: '#2cd07e',
                    confirmButtonText: 'Oui, générer le PDF!'
                }).then((result) => {
                    if (result.isConfirmed) {
                        Swal.fire(
                            'Message',
                            'PDF générer!',
                            'success'
                        );
                        $('#submit').submit();
                    }
                });
            }
        });
    </script>
@endsection
