@extends('layout')

@section('contenu')
    @include('/partials/modalCours')
    @include('/partials/modalNotes')
    @include('/partials/modalBulletin')
    @include('/partials/modalFacture')
    @include('/partials/modalClassPromos')
    @include('/partials/modalRapportPaiement')
    <section
        style="background-image: url('/img/bgclasse.png'); background-attachment: fixed; background-repeat: no-repeat; background-size: cover; min-height: 93.2vh"
        class="section p-0 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>
            <section class="info-tiles">
                <div
                    class="has-text-centered is-flex is-justify-content-center is-justify-content-space-around is-flex-wrap-wrap">
                    <a onclick="openForm('modal_cours')" class="button is-info is-rounded mb-3">
                        <span>Remplir cahier de texte</span>
                    </a>
                    <a href="/accueil/classe/{{ $classe->slug }}/coursHistory" class="button is-info is-rounded mb-3">
                        <span>Historique des cours</span>
                    </a>
                    <a href="/accueil/classe/{{ $classe->slug }}/evaluationHistory" class="button is-info is-rounded mb-3">
                        <span>Historique des évaluations</span>
                    </a>
                    <a onclick="get_classe_slug('{{ $classe->slug }}') ; openForm('modal_notes')"
                        class="button is-info is-rounded mb-3">
                        <span>Enregistrer des notes</span>
                    </a>
                </div>
                <div class="tile is-ancestor has-text-centered">
                    <div class="tile is-parent">
                        <article class="tile is-child box">
                            <p class="title is-4">Effectif</p>
                            <p class="subtitle">{{ $classe->effectif }}</p>
                        </article>
                    </div>
                    <div class="tile is-parent">
                        <article class="tile is-child box">
                            <p class="title is-4">Evaluations</p>
                            <p class="subtitle">
                                {{ count($classe->evaluations->where('promo', auth()->user()->current_year)) }}</p>
                        </article>
                    </div>
                    <div class="tile is-parent">
                        <article class="tile is-child box">
                            <p class="title is-4">Moyenne</p>
                            <p class="subtitle">{{ round($moyenneClasse, 2) }}</p>
                        </article>
                    </div>
                </div>
            </section>
            <div class="box is-flex is-justify-content-center is-justify-content-space-around is-flex-wrap-wrap">
                @if ($evaluations1->count() != 0)
                    <div class="box mb-4">
                        <canvas id="chartClasse1"></canvas>
                    </div>
                @endif
                @if ($evaluations2->count() != 0)
                    <div class="box mb-4">
                        <canvas id="chartClasse2"></canvas>
                    </div>
                @endif
                @if ($evaluations3->count() != 0)
                    <div class="box mb-4">
                        <canvas id="chartClasse3"></canvas>
                    </div>
                @endif
            </div>
            <nav class="panel is-info has-background-light">
                <p class="panel-heading">
                    Liste des élèves
                </p>
                @if (auth()->user()->role == 'administration' || auth()->user()->role == 'surveillant')
                    <div
                        class="has-text-centered is-flex is-justify-content-center is-justify-content-space-around is-flex-wrap-wrap">
                        <div class="panel-block columns mx-0 is-centered my-1">
                            <button class="button is-rounded is-info" onclick="openForm('modalBulletin')">
                                <span class="icon">
                                    <i class="fas fa-clipboard"></i>
                                </span>
                                <span>Bulletins</span>
                            </button>
                        </div>
                        @if (auth()->user()->role == 'administration')
                            <div class="panel-block columns mx-0 is-centered my-1">
                                <button class="button is-rounded is-info" onclick="openForm('modal_facture')">
                                    <span class="icon">
                                        <i class="fas fa-solid fa-file-invoice-dollar"></i>
                                    </span>
                                    <span>Factures</span>
                                </button>
                            </div>
                        @endif
                        @if (auth()->user()->role == 'administration')
                            <div class="panel-block columns mx-0 is-centered my-1">
                                <button class="button is-rounded is-info" onclick="openForm('modal_rapport_paiement')">
                                    <span class="icon">
                                        <i class="fas fa-solid fa-receipt"></i>
                                    </span>
                                    <span>Rapport</span>
                                </button>
                            </div>
                        @endif
                        <div class="panel-block columns mx-0 is-centered my-1">
                            <button class="button is-rounded is-info" onclick="openForm('modalClassPromos')">
                                <span class="icon">
                                    <i class="fas fa-solid fa-graduation-cap"></i>
                                </span>
                                <span>Promos</span>
                            </button>
                        </div>
                    </div>
                @endif
                @if (count($classe->eleves) == 0)
                    <p class="title is-6 has-text-centered pb-4">Aucun élève n'est inscrit dans cette classe</p>
                @else
                    @foreach ($classe->eleves->where('promo', auth()->user()->current_year)->sortBy('nom') as $eleve)
                        <div class="columns mx-0 px-2 is-flex is-flex-wrap-nowrap">
                            <div class="column is-narrow">
                                <a href="/accueil/classe/{{ $classe->slug }}/eleve/{{ $eleve->slug }}" class="panel-block">
                                    <span class="panel-icon">
                                        <i class="fas fa-user-graduate" aria-hidden="true"></i>
                                    </span>
                                    {{ $eleve->prenom }} {{ $eleve->nom }}
                                </a>
                            </div>
                        </div>
                    @endforeach
                @endif
            </nav>
        </section>
    </section>
    @include('/partials/coursJs')
    @include('/partials/classeJs')
    @include('/partials/facturesJs')
    @include('/partials/notesJs')
    @include('/partials/rapportPaiementJs')
@endsection
