@extends('layouts.base')
@section('menu')
    @include('admin.menu')
@endsection
@section('content')

<section class="demandes-details bg-light py-5">
    <div class="container">
        <!-- Header -->
        <div class="header d-flex justify-content-between align-items-center mb-4">
            <h1 class="text-primary">Liste des alumnis</h1>
        </div>

        <!-- Barre de Recherche -->
        <form method="GET" action="{{ route('admin.show-alumnis') }}" class="mb-4" id="search-form">
                      <div class="row">
                          <div class="col-md-6">
                              <input 
                                  type="text" 
                                  name="query" 
                                  class="form-control" 
                                  placeholder="Rechercher..." 
                                  value="{{ request('query') }}" 
                              />
                          </div>
                          <div class="col-md-2">
                              <button type="submit" class="btn btn-primary">Rechercher</button>
                          </div>
                      </div>
                  </form>
                    @if(request('query') && $users->isEmpty())
                        <div class="alert alert-warning">
                            Aucun résultat trouvé pour "{{ request('query') }}".
                        </div>
                    @endif


        <!-- Liste des demandes d'inscription -->
        <div class="card shadow-sm">
            <div class="card-body">
                <hr>

                <!-- Table des utilisateurs -->
                <table class="table table-bordered">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>Nom et prenoms de l'utilisateur</th>
                            <th>Date de l'inscription</th>
                            <th>Email</th>
                            <th>Statut</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        @forelse ($users as $user)
                            <tr>
                                <td>{{ $loop->iteration + (($users->currentPage() - 1) * $users->perPage()) }}</td>
                                <td>{{ $user->name }} {{ $user->surname }}</td>
                                <td>{{ (new \DateTime($user->created_at))->format('d/m/Y') }}</td>
                                <td>{{ $user->email }}</td>
                                <td>
                                    <span class="badge badge-{{ $user->status === 'en attente' ? 'warning' : ($user->status === 'accepter' ? 'success' : 'danger') }}">
                                        {{ ucfirst($user->status) }}
                                    </span>
                                </td>
                                <td>
                                        <a href="{{ route('admin.show-details-alumnis', $user->id) }}" class="btn btn-info btn-sm">
                                            Voir Détails
                                        </a>
                                </td>
                            </tr>
                        @empty
                            <tr>
                                <td colspan="5" class="text-center">Aucun utilisateur trouvé.</td>
                            </tr>
                        @endforelse
                    </tbody>
                </table>

                <!-- Pagination -->
                <div class="d-flex justify-content-center">
                    {{ $users->appends(request()->input())->links() }}
                </div>
            </div>
        </div>
    </div>
</section>
@endsection
