<!-- Ajouter cours========================================================= -->
<div class="modal animate__animated animate__fadeInLeft" id="modal_cours">
    <div onclick="closeForm('modal_cours')" class="modal-background"></div>
    <div class="modal-card">
        <header class="modal-card-head">
            <p class="modal-card-title">Remplir le cahier de texte</p>
            <button type="button" onclick="closeForm('modal_cours')" class="delete" aria-label="close"></button>
        </header>
        <section class="modal-card-body">
            <div class="content">
                <form id="form_cours">
                    @csrf
                    <div class="field">
                        <label class="label title is-6" for="description_id">Description du cours</label>
                        <p class="control">
                            <textarea id="description_id" class="textarea is-info is-rounded
                                @error('description') is-invalid @enderror"
                                placeholder="Donnez les détails du cours" name="description" required></textarea>
                        </p>
                        @error('description')
                            <div class="help is-danger error">{{ $message }}</div>
                        @enderror
                    </div>
                    <div class="field mb-5">
                        <label class="label title is-6" for="prof_id">Professeur</label>
                        @if (auth()->user()->role == 'administration' || auth()->user()->role == 'surveillant')
                            <div class="control">
                                <div class="select is-info is-rounded">
                                    <select id="prof_id" name="prof" class="@error('prof') is-invalid @enderror"
                                        required>
                                        <option value="" disabled selected>Sélectionner</option>
                                        @if ($classe->type == 'Primaire')
                                            @foreach ($professeurs->sortBy('nom') as $professeur)
                                                @if ($professeur->niveau == 'Primaire')
                                                    <option value="{{ $professeur->id }}">{{ $professeur->prenom }}
                                                        {{ $professeur->nom }}</option>
                                                @endif
                                            @endforeach
                                        @else
                                            @foreach ($professeurs->sortBy('nom') as $professeur)
                                                @if ($professeur->niveau == 'Secondaire')
                                                    <option value="{{ $professeur->id }}">{{ $professeur->prenom }}
                                                        {{ $professeur->nom }}</option>
                                                @endif
                                            @endforeach
                                        @endif
                                    </select>
                                </div>
                            </div>
                        @else
                            @foreach ($professeurs as $professeur)
                                @if (str_replace(' ', '', $professeur->telephone) == auth()->user()->nom_utilisateur)
                                    <div class="control">
                                        <div class="select is-info is-rounded">
                                            <select id="prof_id" name="prof" class="@error('prof') is-invalid @enderror"
                                                required>
                                                <option value="{{ $professeur->id }}" selected>
                                                    {{ $professeur->prenom }} {{ $professeur->nom }}</option>
                                            </select>
                                        </div>
                                    </div>
                                @endif
                            @endforeach
                        @endif
                        @error('prof')
                            <div class="help is-danger error">{{ $message }}</div>
                        @enderror
                    </div>
                    <div class="field mb-5">
                        <label class="label title is-6" for="matiere_id">Matière</label>
                        <div class="control">
                            <div class="select is-info is-rounded">
                                <select id="matiere_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 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">
                        <label class="label title is-6" for="debut_id">Heure de début</label>
                        <p class="control">
                            <input id="debut_id"
                                class="input is-info is-rounded
                                @error('debut') is-invalid @enderror"
                                type="time" name="debut" required />
                        </p>
                        @error('debut')
                            <div class="help is-danger error">{{ $message }}</div>
                        @enderror
                    </div>
                    <div class="field">
                        <label class="label title is-6" for="fin_id">Heure de fin</label>
                        <p class="control">
                            <input id="fin_id"
                                class="input is-info is-rounded
                                @error('fin') is-invalid @enderror"
                                type="time" name="fin" required />
                        </p>
                        @error('fin')
                            <div class="help is-danger error">{{ $message }}</div>
                        @enderror
                    </div>
                    <header class="modal-card-head">
                        <p class="modal-card-title">Marquez les absents</p>
                    </header>
                    <section class="modal-card-body">
                        <div class="content">
                            @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 type="checkbox" class="checkbox_absence" value="{{ $eleve->id }}"
                                            title="Cochez pour marquer absent">
                                    </div>
                                </div>
                            @endforeach
                        </div>
                    </section>
                    <button id="submit_form_cours" hidden></button>
                    <button type="reset" class="btn_reset" hidden></button>
                </form>
            </div>
        </section>
        <footer class="modal-card-foot">
            <button type="button" onclick="closeForm('modal_cours')"
                class="button is-light is-danger is-rounded">Annuler</button>
            <button
                onclick="get_id({{ $classe->id }}); get_classe_slug('{{ $classe->slug }}'); $('#submit_form_cours').click()"
                class="button is-info is-link is-rounded">Valider</button>
        </footer>
    </div>
</div>
