@extends('layouts.app')

@section('content')
    <div class="container">
        @if(sizeof($projets) > 0)
            <h2 class="pb-2">Recherche de projets : "{{ $recherche }}"</h2>

            <table class="table table-striped table-bordered">
                <thead>
                <tr>
                    <th>Information</th>
                    <th>Objet</th>
                    <th>Description</th>
                    <th>Dates</th>
                    @can('edit_projet')
                        <th>Actions</th>
                    @endcan
                </tr>
                </thead>
                <tbody>
                @foreach($projets as $p)
                    <tr>
                        <td>
                            {{ $p->reference }}<br>
                            {{ $p->acheteur->nom_complet() }}
                        </td>
                        <td>{{ $p->objet }}</td>
                        <td>@if($p->description != null) {{ $p->description }} @else - @endif</td>
                        <td class="text-right">
                            Créé le {{ date('d/m/Y', strtotime($p->created_at)) }} <br>
                            Mis à jour le {{ date('d/m/Y', strtotime($p->updated_at)) }}
                        </td>
                        @can('edit_projet')
                            <td style="width: 10%;">
                                @if(App\Models\Projet::checkIfUserCanEditOrDestroy($p, true))
                                    <a class="btn btn-outline-primary" href="{{ route('projets.edit', $p->id) }}" 
                                        data-toggle="tooltip" data-placement="top" title="Editer">
                                        <i class="fas fa-pencil-alt"></i>
                                    </a>
                                @endif
                                <form class="inline-form-table" action="{{ route('projets.dupliquer', $p->id) }}" method="POST">
                                    @csrf
                                    {{ method_field('POST') }}
                                    <button type="submit" class="btn btn-outline-info"
                                        data-toggle="tooltip" data-placement="top" title="Dupliquer">
                                        <i class="fas fa-clone"></i>
                                    </button>
                                </form>
                            </td>
                        @endcan
                    </tr>
                @endforeach
                </tbody>
            </table>
        @else
            <h2 class="pb-2">Pas de résultat pour la recherche : "{{ $recherche }}"</h2>
        @endif
    </div>
@endsection
