<!-- Marquez les absents -->
<div class="modal animate__animated animate__fadeInLeft" id="modal_notes">
    <div onclick="closeForm('modal_notes')" class="modal-background"></div>
    <div class="modal-card">
        <header class="modal-card-head">
            <p class="modal-card-title">Enregistrer des notes</p>
            <button type="button" onclick="closeForm('modal_notes')" class="delete" aria-label="close"></button>
        </header>
        <section class="modal-card-body">
            <div class="content">
                <form id="form_notes">
                    @csrf
                    <div class="field mb-5">
                        <label class="label title is-6" for="matiere_evaluee_id">Matière</label>
                        <div class="control">
                            <div class="select is-info is-rounded">
                                <select id="matiere_evaluee_id" name="matiere"
                                    class="@error('matiere') is-invalid @enderror" required>
                                    <option value="" disabled selected>Sélectionner</option>
                                    @if ($classe->type == 'Primaire')
                                        @if (auth()->user()->role == 'professeur')
                                            @foreach ($professeurs as $professeur)
                                                @if (str_replace(' ', '', $professeur->telephone) == auth()->user()->nom_utilisateur)
                                                    @foreach ($professeur->matieres as $matiere)
                                                        @if ($matiere->niveau == 'Primaire')
                                                            <option value="{{ $matiere->id }}">
                                                                {{ $matiere->libelle }}</option>
                                                        @endif
                                                    @endforeach
                                                @endif
                                            @endforeach
                                        @else
                                            @foreach ($matieres as $matiere)
                                                @if ($matiere->niveau == 'Primaire')
                                                    <option class="{{$matiere->coefficient}}" value="{{ $matiere->id }}">{{ $matiere->libelle }}
                                                    </option>
                                                @endif
                                            @endforeach
                                        @endif
                                    @else
                                        @if (auth()->user()->role == 'professeur')
                                            @foreach ($professeurs as $professeur)
                                                @if (str_replace(' ', '', $professeur->telephone) == auth()->user()->nom_utilisateur)
                                                    @foreach ($professeur->matieres as $matiere)
                                                        @if ($matiere->niveau == 'Secondaire')
                                                            <option value="{{ $matiere->id }}">
                                                                {{ $matiere->libelle }}</option>
                                                        @endif
                                                    @endforeach
                                                @endif
                                            @endforeach
                                        @else
                                            @foreach ($matieres as $matiere)
                                                @if ($matiere->niveau == 'Secondaire')
                                                    <option value="{{ $matiere->id }}">{{ $matiere->libelle }}
                                                    </option>
                                                @endif
                                            @endforeach
                                        @endif
                                    @endif
                                </select>
                            </div>
                        </div>
                        @error('matiere')
                            <div class="help is-danger error">{{ $message }}</div>
                        @enderror
                    </div>
                    <div class="field mb-5">
                        <label class="label title is-6" for="type_evaluation_id">Type de Note</label>
                        <div class="control">
                            <div class="select is-info is-rounded">
                                <select id="type_evaluation_id" name="type" class="@error('type') is-invalid @enderror"
                                    required>
                                    <option value="" disabled selected>Sélectionner</option>
                                    @if ($classe->type == 'Primaire')
                                        <option value="Contrôle">Contrôle</option>
                                        <option value="Composition">Composition</option>
                                    @else
                                        <option value="Devoir">Devoir</option>
                                        <option value="Examen">Examen</option>
                                    @endif
                                </select>
                            </div>
                        </div>
                        @error('type')
                            <div class="help is-danger error">{{ $message }}</div>
                        @enderror
                    </div>
                    <div class="field mb-5">
                        <label class="label title is-6" for="semestre_id">Trimestre/Semestre</label>
                        <div class="control">
                            <div class="select is-info is-rounded">
                                <select id="semestre_id" name="semestre" class="@error('semestre') is-invalid @enderror"
                                    required>
                                    <option value="" disabled selected>Sélectionner</option>
                                    @if ($classe->type == 'Primaire')
                                        <option value="1">Trimestre 1</option>
                                        <option value="2">Trimestre 2</option>
                                        <option value="3">Trimestre 3</option>
                                    @else
                                        <option value="1">Semestre 1</option>
                                        <option value="2">Semestre 2</option>
                                        <option value="1">Trimestre 1</option>
                                        <option value="2">Trimestre 2</option>
                                        <option value="3">Trimestre 3</option>
                                    @endif
                                </select>
                            </div>
                        </div>
                        @error('semestre')
                            <div class="help is-danger error">{{ $message }}</div>
                        @enderror
                    </div>
                    <div class="field">
                        <label class="label title is-6" for="date_id">Date d'évaluation</label>
                        <div class="control">
                            <input type="date" id="date_evaluation_id" name="date"
                                class="input is-info is-rounded @error('date') is-invalid @enderror" required>
                        </div>
                        @error('date')
                            <div class="help is-danger error">{{ $message }}</div>
                        @enderror
                    </div>
                    @foreach ($classe->eleves->where('promo', env('SCHOOL_YEAR'))->sortBy('nom') as $eleve)
                        <div class="panel-block is-flex is-justify-content-space-between">
                            <div>
                                <span class="panel-icon">
                                    <i class="fas fa-user-graduate" aria-hidden="true"></i>
                                </span>
                                {{ $eleve->prenom }} {{ $eleve->nom }}
                            </div>
                            <div>
                                <input id="{{ $eleve->id }}" min="0"
                                    max="{{ $classe->type == 'Primaire' ? '60' : '20' }}" type="number"
                                    class="input is-info is-rounded note_eleve"
                                    title="{{ $classe->type == 'Primaire' ? 'Respectez le barême' : 'Entre 0 et 20' }}"
                                    name="note{{ $eleve->id }}" placeholder="00" required>
                            </div>
                        </div>
                    @endforeach
                    <button id="submit_form_notes" hidden></button>
                    <button type="reset" class="btn_reset" hidden></button>
                </form>
            </div>
        </section>
        <footer class="modal-card-foot">
            <button type="button" onclick="closeForm('modal_notes')"
                class="button is-light is-danger is-rounded">Annuler</button>
            <button
                onclick="recupNotes(); getClasseLibelle('{{ $classe->libelle }}'); $('#submit_form_notes').click();"
                class="button is-info is-link is-rounded">Valider</button>
        </footer>
    </div>
</div>
