@extends('layouts.base')

@section('menu')
    @include('etudiants.menu')
@endsection

@section('content')
   
    <section class="courses-listing bg-gray">
        <div class="container-fluid">
        <div class="header d-flex justify-content-between align-items-center mb-4">
                  
              </div>
              <div class="header d-flex justify-content-between align-items-center mb-4">
            <h1 class="text-primary">Mon Profil</h1>
            <a href="{{ route('etudiants.offres.index') }}" class="btn btn-outline-primary">
                <i class="bi bi-arrow-left"></i> Retour à l'accueil  
            </a>
        </div>
                <!-- Barre de Recherche -->
                  <form method="GET" action="{{ route('alumnis.degree') }}" 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()->filled('query') && $degrees->isEmpty())
                        <div class="alert alert-warning">
                            Aucun résultat trouvé pour "{{ request('query') }}".
                        </div>
                    @endif

            <div class="courses-table-body">
                
              <table id="offresTable" class="table table-hover table-responsive-xl" style="width: 100%;"> 
                    <thead>
                        <tr>
                            <th>N°</th>
                            <th>Nom</th>
                            <th>Ecole/centre</th>
                            <th>Domaine</th>
                            <th>Description</th>
                            <th>Type</th>
                            <th>Date de debut</th>
                            <th>Date de fin</th>
                            <th>Document</th>
                            <th>Actions</th>
                        </tr>
                    </thead>  
                <tbody>
                @foreach($degrees as $degree)
                        <tr>
                            <td>{{ $loop->iteration }}</td>
                            <td>{{ $degree->name }}</td>
                            <td>{{ $degree->school_name }}</td> 
                            <td>{{ $degree->domain }}</td>
                            <td>{{ $degree->description }}</td>
                            <td>{{ $degree->type }}</td>
                            <td>{{ $degree->start_date->format('Y-m-d') }}</td>
                            <td>{{ $degree->end_date ? $degree->end_date->format('Y-m-d') : 'Non spécifiée' }}</td>
                            <td>
                                @if($degree->media_path)
                                <a style="margin-bottom: 5px; margin-right: 2px;" href="{{ asset('storage/' . $degree->media_path) }}" target="blank"class="btn btn-primary" title="voir le fichier">
                            <i class="fa fa-eye" aria-hidden="true"></i>
                        </a><a style="margin-bottom: 5px;" href="{{ asset('storage/' . $degree->media_path) }}" class="btn btn-primary" title="Télécharger le fichier" download="">
                            <i class="fa fa-download" aria-hidden="true"></i>
                        </a>
                                
                                @else
                                    Aucun fichier
                                @endif
                            </td>
                            <td>
                           
                                    <a class="btn btn-warning" href="{{ route('alumnis.updateDegree', $degree->id)}}">Modifier</a>
                                    
                                    <button class="btn btn-danger btn-sm" data-bs-toggle="modal" data-bs-target="#deleteModal">
                                        Supprimer</button>
                                </form>
                            </td>
                        </tr>
                        <!-- Modal pour Rejeter -->
                        <div class="modal fade" id="deleteModal" tabindex="-1" aria-labelledby="deleteModalLabel" aria-hidden="true">
                            <div class="modal-dialog">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <h5 class="modal-title" id="deleteModalLabel">Confirmer la suppression</h5>
                                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                                    </div>
                                    <form action="{{ route('destroy',$degree->id) }}" method="POST">

                                        @csrf
                                        @method('DELETE')
                                        <div class="modal-body">
                                            <p>Êtes-vous sûr de vouloir supprimer cette formation ?</p>
                                    
                                        </div>
                                        <div class="modal-footer">
                                            <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Annuler</button>
                                            <button type="submit" class="btn btn-danger">Supprimer</button>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                @endforeach
                </tbody>
              </table>
            </div>
          </div>
          <nav aria-label="Page navigation example" class="d-flex justify-content-center">
            <ul class="pagination">
              <li class="page-item"><a href="#" aria-label="Previous" class="page-link"><span aria-hidden="true">«</span><span class="sr-only">Previous</span></a></li>
              <li class="page-item active"><a href="#" class="page-link">1</a></li>
              <li class="page-item"><a href="#" class="page-link">2</a></li>
              <li class="page-item"><a href="#" class="page-link">3</a></li>
              <li class="page-item"><a href="#" aria-label="Next" class="page-link"><span aria-hidden="true">»</span><span class="sr-only">Next</span></a></li>
            </ul>
          </nav>
        </div>
      </section>



    <!-- Scripts -->
    <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
    <script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
    <script src="https://cdn.datatables.net/1.13.6/js/dataTables.bootstrap5.min.js"></script>
    <script>
       $(document).ready(function () {
    $('#offresTable').DataTable({
        language: {
            url: "https://cdn.datatables.net/plug-ins/1.13.6/i18n/fr-FR.json"
        },
        responsive: true, 
        pageLength: 10, 
        order: [[0, "asc"]] 
    });
});


    </script>
<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
@endsection





