@extends('layout')

@section('contenu')
    @include('/partials/modalModifierCours')
    @include('/partials/modalConfirmSuppCours')

    <section
        style="background-image: url('/img/bgclasse.png'); background-attachment: fixed; background-repeat: no-repeat; background-size: cover; min-height: 93.2vh"
        class="section mt-0 columns mx-0 mb-0 is-centered">
        <section class="section container column is-two-thirds">
            <section class="section is-link is-light p-0">
                <h1 class="title is-1 is-size-3-touch has-text-centered has-text-white">{{ $classe->libelle }}</h1>
                <h1 class="subtitle is-6 has-text-centered has-text-white">{{ $classe->type }}</h1>
            </section>
            <nav class="panel is-info has-background-light mt-2">
                <p class="panel-heading mb-3">
                    L'historique des cours déroulés dans cette classe
                </p>
                @if (count($cours) == 0)
                    <p class="title is-6 has-text-centered pb-4">Il n'y pas encore de cours dans cette classe</p>
                @else
                    @if (auth()->user()->role == 'administration' || auth()->user()->role == 'surveillant')
                        @foreach ($cours->sortByDesc('id') as $unCours)
                            <div class="content box">
                                <div class="has-text-weight-bold has-text-success"><span
                                        class="has-text-weight-bold">Date:</span>
                                    {{ date('d/m/Y', strtotime($unCours->created_at)) }}</div>
                                <div><span class="has-text-weight-bold">Détails:</span> {!! nl2br($unCours->description) !!}</div>
                                @foreach ($professeurs as $professeur)
                                    @if ($professeur->id == $unCours->professeur_id)
                                        <div><span class="has-text-weight-bold">Professeur:</span>
                                            {{ $professeur->prenom }}
                                            {{ $professeur->nom }}</div>
                                    @endif
                                @endforeach
                                @foreach ($matieres as $matiere)
                                    @if ($matiere->id == $unCours->matiere_id)
                                        <div><span class="has-text-weight-bold">Matière:</span> {{ $matiere->libelle }}
                                        </div>
                                    @endif
                                @endforeach
                                <div><span class="has-text-weight-bold">Heure de début:</span>
                                    {{ date('H:i', strtotime($unCours->debut)) }}</div>
                                <div><span class="has-text-weight-bold">Heure de fin:</span>
                                    {{ date('H:i', strtotime($unCours->fin)) }}</div>
                                @if (auth()->user()->administrateur == 1)
                                    <div class="buttons">
                                        <a type="button" class="button is-info is-light"
                                            onclick="getCoursId({{ $unCours->id }}); getClasseLib('{{ $classe->libelle }}'); get_classe_slug('{{ $classe->slug }}'); openForm('modalSuppCours')">Supprimer</a>
                                        <a type="button" class="button is-info is-light"
                                            onclick="getCoursId({{ $unCours->id }}); getClasseLib('{{ $classe->libelle }}'); get_classe_slug('{{ $classe->slug }}'); openForm('modal_modifier_cours'); getOldDescrip('{!! str_replace(["\r\n", "\n"], '\n', addslashes($unCours->description)) !!}'); getOldProf({{ $unCours->professeur_id }}); getOldMatiere({{ $unCours->matiere_id }}); getOldDebut('{{ date('H:i', strtotime($unCours->debut)) }}'); getOldFin('{{ date('H:i', strtotime($unCours->fin)) }}');">Modifier</a>
                                    </div>
                                @endif
                            </div>
                        @endforeach
                    @else
                        @foreach ($cours->sortByDesc('id') as $unCours)
                            @foreach ($professeurs as $professeur)
                                @if (str_replace(' ', '', $professeur->telephone) == auth()->user()->nom_utilisateur && $unCours->professeur_id == $professeur->id)
                                    <div class="content box">
                                        <div class="has-text-weight-bold has-text-success"><span
                                                class="has-text-weight-bold">Date:</span>
                                            {{ date('d/m/Y', strtotime($unCours->created_at)) }}</div>
                                        <div><span class="has-text-weight-bold">Détails:</span> {!! nl2br($unCours->description) !!}
                                        </div>
                                        @if ($professeur->id == $unCours->professeur_id)
                                            <div><span class="has-text-weight-bold">Professeur:</span>
                                                {{ $professeur->prenom }}
                                                {{ $professeur->nom }}</div>
                                        @endif
                                        @foreach ($matieres as $matiere)
                                            @if ($matiere->id == $unCours->matiere_id)
                                                <div><span class="has-text-weight-bold">Matière:</span>
                                                    {{ $matiere->libelle }}
                                                </div>
                                            @endif
                                        @endforeach
                                        <div><span class="has-text-weight-bold">Heure de début:</span>
                                            {{ date('H:i', strtotime($unCours->debut)) }}</div>
                                        <div><span class="has-text-weight-bold">Heure de fin:</span>
                                            {{ date('H:i', strtotime($unCours->fin)) }}</div>
                                        @if (auth()->user()->administrateur == 1)
                                            <div class="buttons">
                                                <a type="button" class="button is-info is-light"
                                                    onclick="getCoursId({{ $unCours->id }}); getClasseLib('{{ $classe->libelle }}'); get_classe_slug('{{ $classe->slug }}'); openForm('modalSuppCours')">Supprimer</a>
                                                <a type="button" class="button is-info is-light"
                                                    onclick="getCoursId({{ $unCours->id }}); getClasseLib('{{ $classe->libelle }}'); get_classe_slug('{{ $classe->slug }}'); openForm('modal_modifier_cours'); getOldDescrip('{!! str_replace(["\r\n", "\n"], '\n', addslashes($unCours->description)) !!}'); getOldProf({{ $unCours->professeur_id }}); getOldMatiere({{ $unCours->matiere_id }}); getOldDebut('{{ date('H:i', strtotime($unCours->debut)) }}'); getOldFin('{{ date('H:i', strtotime($unCours->fin)) }}');">Modifier</a>
                                            </div>
                                        @endif
                                    </div>
                                @endif
                            @endforeach
                        @endforeach
                    @endif

                @endif
            </nav>
        </section>
    </section>
    @include('/partials/coursJs')

@endsection
