@extends('admin.template')

@section('sidebar')
    <aside id="sidebar" class="sidebar">

        <ul class="sidebar-nav" id="sidebar-nav">

            <li class="nav-item">
                <a class="nav-link " href="{{ url('admin') }}">
                    <i class="bi bi-grid"></i>
                    <span>Tableau de Bord</span>
                </a>
            </li><!-- End Dashboard Nav -->

            <li class="nav-item">
                <a class="nav-link collapsed" data-bs-target="#components-nav" data-bs-toggle="collapse" href="#">
                    <i class="bi bi-menu-button-wide"></i><span>Gestion des livres </span><i
                        class="bi bi-chevron-down ms-auto"></i>
                </a>
                <ul id="components-nav" class="nav-content collapse" data-bs-parent="#sidebar-nav">
                    <li>
                        <a href="{{ url('admin/consulter_book') }}">
                            <i class="bi bi-circle"></i><span>Livres disponibles </span>
                        </a>
                    </li>
                    <li>
                        <a href="{{ url('admin/add') }}">
                            <i class="bi bi-circle"></i><span>Ajouter un livre</span>
                        </a>
                    </li>
                    <li>
                        <a href="{{ url('admin/supp') }}">
                            <i class="bi bi-circle"></i><span>Livres supprimés</span>
                        </a>
                    </li>
                    <li>
                        <a href="{{ url('admin/attente') }}">
                            <i class="bi bi-circle"></i><span>Livres en attente </span>
                        </a>
                    </li>
                    

                </ul>


            <li class="nav-item">
                <a class="nav-link collapsed" data-bs-target="#forms-nav" data-bs-toggle="collapse" href="#">
                    <i class="bi bi-journal-text"></i><span>Documentations </span><i
                        class="bi bi-chevron-down ms-auto"></i>
                </a>
                <ul id="forms-nav" class="nav-content collapse " data-bs-parent="#sidebar-nav">
                    <li>
                        <a href="{{ url('admin/add_document') }}">
                            <i class="bi bi-circle"></i><span>Ajouter un document </span>
                        </a>
                    </li>
                    <li>
                        <a href="{{ url('admin/supp_document') }}">
                            <i class="bi bi-circle"></i><span>Documents supprimés  </span>
                        </a>
                    </li>
                    <li>
                        <a href="{{ url('admin/consulter') }}">
                            <i class="bi bi-circle"></i><span>Documents disponibles </span>
                        </a>
                    </li>
                </ul>
            </li><!-- End Forms Nav -->
            <li class="nav-heading">Pages</li>

            <li class="nav-item">
                <a class="nav-link collapsed" href="{{ route('profil',  0) }}">
                    <i class="bi bi-person"></i>
                    <span>Profil</span>
                </a>
            </li><!-- End Profile Page Nav -->

            <li class="nav-item">
                <a class="nav-link collapsed" href="{{ url('admin/pages-faq') }}">
                    <i class="bi bi-question-circle"></i>
                    <span>Aide</span>
                </a>
            </li><!-- End F.A.Q Page Nav -->


        </ul>

    </aside>
@endsection


@section('main')
    <main id="main" class="main">

        <div class="pagetitle">
            <h1>Messages</h1> 
        </div><!-- End Page Title -->

        <section class="section">
            <div class="row">
              <div class="col-12">
                <div class="card recent-sales overflow-auto">
  
                  <div class="card-body">
                    <h5 class="card-title">Message des utilisateurs</h5>
  
                    <table class="table table-borderless datatable">
                      <thead>
                        <tr>
                          <th scope="col">#</th>
                          <th>Nom</th>
                          <th>Email</th>
                          <th>Objet</th>
                          <th>Message</th>
                          <th>Action</th>
                        </tr>
                      </thead>
                      <tbody>
                        @foreach ($messages as $contact)
                          <tr>
                            <td>{{$contact->id}}</td>
                          <td>{{$contact->vnom}}</td>
                          <td>{{$contact->email}}</td>
                          <td>{{$contact->objet}}</td>
                          <td>{{ substr($contact->commentaire, 0, 40)}}...</td>
                          <td class="text-center">
                            <a href="{{route('read_msg',$contact->id)}}"><button class="btn text-white bg-primary" >Lire</button></a>
                            <form class="form1" id="form1" method="post"
                                        onsubmit="return supprimerMsg(this);">
                                        @csrf
                                        <input type="text" id="id" name="id"
                                            value="{{ $contact->id }}"
                                            style="display: none;">
                                        <button class="btn btn-danger" type="submit"><i class="bi bi-trash"></i></button>
                                    </form>
                                
                        </td>
                          </tr>
                          
                        @endforeach
                      </tbody>
                    </table>
  
                  </div>
  
                </div>
              </div>

        </section>

    </main>
    <div class="modal fade" id="confModal4" tabindex="-1" role="dialog" aria-
                            labelledby="confModalLabel4" aria-hidden="true">
                            <div class="modal-dialog" role="document">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <h5 id="confModalLabel4" class="text-center">Souhaitez-vous vraiment supprimer ce message ?</h5>
                                        <button type="button" class="close" data-bs-dismiss="modal" aria-
                                            label="Close">
                                            <span aria-hidden="true">&times;</span>
                                        </button>
                                    </div>
                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-default"
                                            data-bs-dismiss="modal">Annuler</button>
                                        <form id="formMsg" action="" method="post">
                                            @method('DELETE')
                                            @csrf
                                            <button type="submit" class="btn btn-danger">Supprimer</button>
                                        </form>

                                    </div>
                                </div>
                            </div>
                        </div>
    @if (session()->has('success'))
        <script src="/js/jquery-3.2.1.min.js"></script>
        <a type="button" id="lien2" data-bs-toggle="modal" data-bs-target="#confModal2" style="display: none;">appui</a>
        <script type="text/javascript">
            $(window).on('load',function(){
            $('#confModal2').modal('show');
            });
        </script>
        <!-- Fenetre modale 2-->

        <div class="modal fade" id="confModal2" tabindex="-1" role="dialog" aria-
        labelledby="confModalLabel2" aria-hidden="true">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title text-success text-center" id="confModalLabel2">{{ session('success') }}</h5>
                            <button type="button" class="close" data-bs-dismiss="modal" aria-
                            label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-success" data-bs-dismiss="modal">D'accord</button>
                    </div>
                </div>
            </div>
        </div>
        <!-- Fin fenetre modale 2-->
    @elseif (session()->has('error'))
        <script src="/js/jquery-3.2.1.min.js"></script>
        <script type="text/javascript">
            $(window).on('load',function(){
            $('#confModal3').modal('show');
            });
        </script>
        <!-- Fenetre modale 3-->

        <div class="modal fade" id="confModal3" tabindex="-1" role="dialog" aria-
        labelledby="confModalLabel3" aria-hidden="true">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title text-danger text-center" id="confModalLabel2">{{ session('error') }} error</h5>
                            <button type="button" class="close" data-bs-dismiss="modal" aria-
                            label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-danger" data-bs-dismiss="modal">D'accord</button>
                    </div>
                </div>
            </div>
        </div>
        <!-- Fin fenetre modale 3-->
        @endif
@endsection
