@extends('layout')

@section('contenu')
    <section
        style="background-image: url('/img/login.png'); background-attachment: fixed; background-repeat: no-repeat; background-size: cover; min-height: 93.2vh"
        class="section">
        <section class="section is-link is-light">
            <h1 class="title is-1 is-size-3-touch has-text-centered has-text-white"> Bienvenue sur UpSchool </h1>
            <h1 class="subtitle is-6 has-text-centered has-text-white"> Une meilleure vision de l'éducation</h1>
        </section>

        <!-- LES CLASSES =============================================================  -->

        <section>
            <!-- Ajouter classe ======================================================= -->

            @include('/partials/modalClasse')
            @include('/partials/modalModifierClasse')

            <!-- Supprimer classe -->
            @include('/partials/modalConfirmSuppClasse')

            @include('/partials/modalDetailsOperation')
            @include('/partials/modalAjouterOperation')
            @include('/partials/modalModifierOperation')
            @include('/partials/modalConfirmSuppOperation')

            <!-- end =================================================================== -->

            <!-- Panel ================================================================= -->

            <div class="columns mx-0">
                <div class="column mr-1 mt-2 mb-0 is-half box">
                    <canvas id="myChartPrimaire"></canvas>
                </div>
                <div class="column mt-2 is-half box">
                    <canvas id="myChartSecondaire"></canvas>
                </div>
            </div>

            <div class="columns mx-0 mt-6">
                <div class="column p-5-desktop mx-3-desktop mx-0-mobile p-0-mobile">
                    <article class="panel has-background-white">
                        <p class="panel-heading">
                            Classes
                        </p>
                        @if (auth()->user()->administrateur == 1)
                            <div class="panel-block is-justify-content-center">
                                <div>
                                    <a onclick="openForm('modalFormClasse')" class="button is-info is-rounded">
                                        <strong>Ajouter une classe</strong>
                                    </a>
                                </div>
                            </div>
                        @endif
                        <div style="height: 20rem; overflow-y: auto;">
                            @if (auth()->user()->role == 'administration' || auth()->user()->role == 'surveillant')
                                @foreach ($classes as $classe)
                                    <div class="columns is-flex mx-0">
                                        <div class="column p-0 pt-4 is-three-quarters">
                                            <a href="/accueil/classe/{{ $classe->slug }}" class="panel-block">
                                                <span class="panel-icon">
                                                    <i class="fas fa-graduation-cap" aria-hidden="true"></i>
                                                </span>
                                                {{ $classe->libelle }}
                                            </a>
                                        </div>
                                        @if (auth()->user()->administrateur == 1)
                                            <div class="column p-0 pt-4 is-flex is-justify-content-right">
                                                <a style="color: #3E8ED0" title="Modifier"
                                                    class="icon is-medium btn_modifier_classe"
                                                    onclick="openForm('modal_modifier_classe'); get_libelle_classe('{{ $classe->libelle }}'); get_id_classe({{ $classe->id }}); get_type_classe('{{ $classe->type }}')">
                                                    <i class="fas fa-edit" aria-hidden="true"></i>
                                                </a>
                                                <a style="color: #3E8ED0" title="Supprimer" class="icon is-medium"
                                                    onclick="get_id_classe({{ $classe->id }}); openForm('modalSuppClasse');">
                                                    <i class="fas fa-trash-alt" aria-hidden="true"></i>
                                                </a>
                                            </div>
                                        @endif
                                    </div>
                                @endforeach
                            @elseif(auth()->user()->role == 'professeur')
                                @foreach ($professeurs as $professeur)
                                    @if (str_replace(' ', '', $professeur->telephone) == auth()->user()->nom_utilisateur)
                                        @foreach ($professeur->classes as $classe)
                                            <div class="columns is-flex mx-0">
                                                <div class="column p-0 pt-4 is-three-quarters">
                                                    <a href="/accueil/classe/{{ $classe->slug }}" class="panel-block">
                                                        <span class="panel-icon">
                                                            <i class="fas fa-graduation-cap" aria-hidden="true"></i>
                                                        </span>
                                                        {{ $classe->libelle }}
                                                    </a>
                                                </div>
                                            </div>
                                        @endforeach
                                    @endif
                                @endforeach
                            @endif
                        </div>
                    </article>
                </div>
                @if (auth()->user()->role == 'administration')
                    <div class="column p-5-desktop mx-3-desktop mx-0-mobile p-0-mobile">
                        <article class="panel is-info has-background-white">
                            <p class="panel-heading">
                                Transactions
                            </p>
                            <div class="panel-block is-justify-content-center">
                                <div>
                                    <a onclick="openForm('modalAjouterOperation')" class="button is-info is-rounded">
                                        <strong>Ajouter transaction</strong>
                                    </a>
                                </div>
                            </div>
                            <div style="height: 20rem;overflow-y: auto;">
                                @if (auth()->user()->administrateur == 1)
                                    @if (count($operations) == 0)
                                        <div class="panel-block is-justify-content-center">
                                            <strong>Aucune Transaction</strong>
                                        </div>
                                    @else
                                        @foreach ($operations as $operation)
                                            <span class="columns is-flex m-auto">
                                                <span class="column is-three-quarters">
                                                    <span class="panel-block">
                                                        <span class="panel-icon">
                                                            <i class="fas fa-money-bill" aria-hidden="true"></i>
                                                        </span>
                                                        {{ $operation->libelle }}({{ $operation->type_operation }}) par
                                                        {{ $operation->user != null ? $operation->user->prenom . ' ' . $operation->user->nom : 'UPGROUP-PAY' }}
                                                        {{ $operation->statut == 'annule' ? ' (Annulee)' : '' }}
                                                    </span>
                                                </span>
                                                <span class="column px-0 is-flex is-justify-content-right">
                                                    <a class="icon is-medium"
                                                        onclick="openForm('modalDetailsOperation'); get_ref_det('{{ $operation->reference }}'); get_libelle_det('{{ addslashes($operation->libelle) }}'); get_type_det('{{ $operation->type_operation }}'); get_descr_det('{{ addslashes($operation->description == null ? '' : $operation->description) }}'); get_montant_det('{{ $operation->montant }}'); get_author_det('{{ $operation->user != null ? $operation->user->prenom . ' ' . $operation->user->nom : 'UPGROUP-PAY' }}'); get_date_det('{{ date('d/m/Y', strtotime($operation->created_at)) }}'); get_update_det('{{ date('d/m/Y', strtotime($operation->updated_at)) }}');">
                                                        <i title="Détails" class="fas fa-info" aria-hidden="true"></i>
                                                    </a>
                                                    <a class="icon is-medium"
                                                        onclick="openForm('modalModifierOperation'); get_id_operation({{ $operation->id }}); get_libelle_operation('{{ addslashes($operation->libelle) }}'); get_type_operation('{{ $operation->type_operation }}'); get_descr('{{ addslashes($operation->description == null ? '' : $operation->description) }}'); get_montant('{{ $operation->montant }}');">
                                                        <i title="Modifier" class="fas fa-edit" aria-hidden="true"></i>
                                                    </a>
                                                    <a class="icon is-medium"
                                                        onclick="get_id_operation({{ $operation->id }}); openForm('modalSuppOperation')">
                                                        <i title="Supprimer" class="fas fa-trash-alt"
                                                            aria-hidden="true"></i>
                                                    </a>
                                                </span>
                                            </span>
                                        @endforeach
                                    @endif
                                @else
                                    @foreach ($userOperations as $operation)
                                        <span class="columns is-flex m-auto">
                                            <span class="column is-three-quarters">
                                                <span class="panel-block">
                                                    <span class="panel-icon">
                                                        <i class="fas fa-money-bill" aria-hidden="true"></i>
                                                    </span>
                                                    {{ $operation->libelle }}({{ $operation->type_operation }})
                                                    {{ $operation->statut == 'annule' ? ' (Annulee)' : '' }}
                                                </span>
                                            </span>
                                            <span class="column px-2 is-flex is-justify-content-right">
                                                <a class="icon is-medium"
                                                    onclick="openForm('modalDetailsOperation'); get_ref_det('{{ $operation->reference }}'); get_libelle_det('{{ addslashes($operation->libelle) }}'); get_type_det('{{ $operation->type_operation }}'); get_descr_det('{{ addslashes($operation->description == null ? '' : $operation->description) }}'); get_montant_det('{{ $operation->montant }}'); get_author_det('{{ $operation->user != null ? $operation->user->prenom . ' ' . $operation->user->nom : 'UPGROUP-PAY' }}'); get_date_det('{{ date('d/m/Y', strtotime($operation->created_at)) }}'); get_update_det('{{ date('d/m/Y', strtotime($operation->updated_at)) }}');">
                                                    <i title="Détails" class="fas fa-info" aria-hidden="true"></i>
                                                </a>
                                            </span>
                                        </span>
                                    @endforeach
                                @endif
                            </div>
                        </article>
                    </div>
                    @if (auth()->user()->role == 'administration')
                        <div class="column p-5-desktop mx-3-desktop mx-0-mobile p-0-mobile">
                            <article class="panel has-background-white">
                                <p class="panel-heading">
                                    Actions
                                </p>
                                <div class="panel-block is-justify-content-center">
                                    <div>
                                        <a style="cursor: grab" class="button is-white is-rounded">
                                            <strong>Les dernières actions</strong>
                                        </a>
                                    </div>
                                </div>
                                <div style="height: 20rem;overflow-y: auto;">
                                    @if (count($notifications) == 0)
                                        <div class="panel-block is-justify-content-center">
                                            <strong>Aucune Action</strong>
                                        </div>
                                    @else
                                        @foreach ($notifications as $notification)
                                            <span class="panel-block">
                                                <span class="panel-icon">
                                                    <i class="fas fa-bell" aria-hidden="true"></i>
                                                </span>
                                                <span class="subtitle is-6">{{ $notification->message }} le
                                                    {{ date('d-m-Y', strtotime($notification->date)) }}</span>
                                            </span>
                                        @endforeach
                                    @endif
                                </div>
                            </article>
                        </div>
                    @endif
                @endif
            </div>
        </section>
    </section>
    <!-- End panel ============================================================= -->
    @include('/partials/homeJs')
    @include('/partials/operationJs')
@endsection
