@extends('layouts.app')

@section('content')
    <div class="container">
        <div>
            <h2 class="pb-2">Structures
                <a class="btn btn-outline-success float-right mb-4" href="{{ route('structures.create') }}">Ajouter</a>
            </h2>
        </div>

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

        @if(sizeof($structures) > 0)
            <table class="table table-striped table-bordered">
                <thead>
                <tr>
                    <th>Nom</th>
                    <th>Description</th>
                    <th>Adresse</th>
                    <th>Consolidation</th>
                    <th>Administrateurs</th>
                    <th>Statut</th>
                    <th>Action</th>
                </tr>
                </thead>
                <tbody>
                @foreach($structures as $s)
                    <tr>
                        <td>
                            {{ $s->nom }}
                        </td>
                        <td>{{ $s->description ?? '-' }}</td>
                        <td>{{ $s->adresse }}, {{ $s->cp }} {{ $s->ville }}</td>
                        <td>{{ $s->consolidation->nom ?? '-' }}</td>
                        <td>{{ $s->administrateurs() ?? '-' }}</td>
                        <td style="width: 5%">
                            <form class="inline-form-table" action="{{ route('structures.active', $s->id) }}" method="POST">
                                @csrf
                                {{ method_field('PUT') }}
                                @if ($s->active)
                                    <button type="submit" class="btn btn-success" 
                                        data-toggle="tooltip" data-placement="top" title="Désactiver">
                                        <i class="fas fa-toggle-on"></i>
                                    </button>
                                @else
                                    <button type="submit" class="btn btn-secondary"
                                    data-toggle="tooltip" data-placement="top" title="Activer">
                                        <i class="fas fa-toggle-off"></i>
                                    </button>
                                @endif
                            </form>
                        </td>
                        <td style="width: 5%">
                            <a class="btn btn-outline-primary" href="{{ route('structures.edit', $s->id) }}"
                                data-toggle="tooltip" data-placement="top" title="Editer">
                                <i class="fas fa-pencil-alt"></i>
                            </a>
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>

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