@extends('layouts.app')

@section('content')
    <div class="container">
        <div>
            <ol class="breadcrumb">
                <li class="breadcrumb-item">{{ $structure->nom }}</li>
                <li class="breadcrumb-item active" aria-current="page">Alertes</li>
            </ol>
            <h2 class="pb-2">Alertes
                @can('add_parametre')
                    <a class="btn btn-outline-success float-right mb-4" href="{{ route('alertes.create') }}">Ajouter</a>
                @endcan
            </h2>
        </div>

        @include('layouts.commons.errors')
        @include('layouts.commons.success')

        @if(sizeof($alertes) > 0)
            <table class="table table-striped table-bordered">
                <thead>
                <tr>
                    <th>Utilisateur</th>
                    <th>Rôle</th>
                    <th>Critère</th>
                    <th>Formule</th>
                    <th>Indicateur ou Critère</th>
                    @canany(array('edit_parametre', 'delete_parametre'))
                        <th>Actions</th>
                    @endcanany
                </tr>
                </thead>
                <tbody>
                    @foreach($alertes as $a)
                        <tr>
                            <td>{{ $a->user->nom_complet() }}</td>
                            <td>{{ $a->user->nom_role(true) }}</td>
                            <td>{{ TEXT::FORMATTED_TEXT[$a->critere] }}</td>
                            <td>{{ $a->formule }}</td>
                            @if($a->est_valeur)
                                @if($a->critere === TEXT::GAINS_NOTIFIES || $a->critere === TEXT::GAINS_CIBLE)
                                    <td>{{ $a->indicateur }} %</td>
                                @else
                                    <td>{{ $a->indicateur }} €</td>
                                @endif
                            @else
                                <td>{{ TEXT::FORMATTED_TEXT[$a->indicateur_critere] }}</td>
                            @endif
                            @canany(array('edit_parametre', 'delete_parametre'))
                                <td style="width: 10%">
                                    @can('edit_parametre')
                                        <a class="btn btn-outline-primary" href="{{ route('alertes.edit', $a->id) }}"
                                            data-toggle="tooltip" data-placement="top" title="Editer">
                                            <i class="fas fa-pencil-alt"></i>
                                        </a>
                                    @endcan
                                    @can('delete_parametre')
                                        <form class="inline-form-table" action="{{ route('alertes.destroy', $a->id) }}" method="POST">
                                            @csrf
                                            {{ method_field('DELETE') }}
                                            <button type="submit" class="btn btn-outline-danger"
                                                data-toggle="tooltip" data-placement="top" title="Supprimer">
                                                <i class="fas fa-trash-alt"></i>
                                            </button>
                                        </form>
                                    @endcan
                                </td>
                            @endcanany
                        </tr>
                    @endforeach
                </tbody>
            </table>

            {{ $alertes->links("pagination::bootstrap-4") }}
        @else
            <div class="pt-2">
                <h4>Pas de données disponible.</h4>
            </div>
        @endif
    </div>
@endsection
