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

@if(Auth::user()->can('edit_projet') && $editable)
    <div class="row mt-2 mb-2">
        <div class="col-12">
            <a href="{{ route('fichiers.create', $projet->id) }}" class="btn btn-outline-success float-right">Ajouter un fichier</a>
        </div>
    </div>
@endif

@if($projet->fichiers->count() > 0)
    <table class="table table-striped table-bordered">
        <thead>
            <th>Fichier</th>
            <th>Déposé par</th>
            <th>Commentaire</th>
            <th>Dates</th>
            @if(Auth::user()->can('edit_projet') && $editable)
                <th>Actions</th>
            @endif
        </thead>
        <tbody>
            @foreach($projet->fichiers as $fichier)
                <tr>
                    <td>
                        <a href="{{ route('fichiers.download', [$projet->id, $fichier->id]) }}">{{ $fichier->nom }}</a>
                    </td>
                    <td>{{ $fichier->user->nom_complet() }}</td>
                    <td>{{ $fichier->commentaire ?? '-' }}</td>
                    <td>
                        Ajouté le {{ date('d/m/Y', strtotime($fichier->created_at)) }}<br>
                        Modifié le {{ date('d/m/Y', strtotime($fichier->updated_at)) }}
                    </td>
                    @if(Auth::user()->can('edit_projet') && $editable)
                        <td style="width: 12%">
                            <a class="btn btn-outline-primary" href="{{ route('fichiers.edit', [$projet->id, $fichier->id]) }}"
                                data-toggle="tooltip" data-placement="top" title="Editer">
                                <i class="fas fa-pencil-alt"></i>
                            </a>
                            <form class="inline-form-table" action="{{ route('fichiers.destroy', [$projet->id, $fichier->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>
                        </td>
                    @endif
                </tr>
            @endforeach
        </tbody>
    </table>
@else
    <div class="pt-2">
        <h4>Pas de données disponible.</h4>
    </div>
@endif
