@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>Résultat de la recherche : {{ $key }}</h1>
            @if(count($result))
                <small>Environ {{ count($result) }} résultat(s)</small>
            @endif
        </div><!-- End Page Title -->

        <section class="section dashboard">
            <div class="row">
                @if (!count($result))
                    <div class="col-10">
                        <p class="text-danger">Aucun livre correspondant...</p>
                    </div>
                @else
                    @foreach ($result as $book)
                        <div class="col-10">
                            <div class="card">
                                <div class="card-header">
                                    <div class="row">
                                        <h4 class="col-8"> <a
                                                href="{{ route('read.book', $book['id']) }}">{{ $book['titre'] }} -
                                                {{ $book['auteur'] }}</a> </h4>
                                        @if ($book['etat'] == 0)
                                            <form id="form1" method="post"
                                                onsubmit="return emprunter(this);">
                                                @csrf
                                                <input type="text" id="iden" name="iden"
                                                    value="{{ $book['id'] }}" style="display: none;">
                                                <input type="text" id="titre" name="titre"
                                                    value="{{ $book['titre'] . '-' . $book['auteur'] }}"
                                                    style="display: none;">
                                                <input type="text" id="vers" name="vers"
                                                    value="{{ 'version ' . $book['version'] . '- ISBN ' . $book['ISBN'] }}"
                                                    style="display: none;">
                                                <button class="btn btn-secondary col-10 text-white" type="submit"
                                                    name="">Valider l'ajout du livre</button>
                                            </form>
                                        @endif
                                    </div>
                                </div>
                                <div class="card-body">
                                    <div class="row">
                                        <div class="col-lg-9 mt-3">
                                            <p> {{ substr($book['description'], 0, 200) }}... </p>
                                            <p class="text-success d-none d-lg-block">
                                                <strong>Très utile en :</strong>
                                                @php
                                                    $i = 0;
                                                    $book_disc = \App\Models\Book_Discipline::all();
                                                    $disciplines = \App\Models\Discipline::all();
                                                @endphp
                                                @foreach ($book_disc as $b_d)
                                                    @if ($b_d['book_id'] == $book['id'])
                                                        @foreach ($disciplines as $discipline)
                                                            @if ($discipline['id'] == $b_d['discipline_id'])
                                                                @if ($i == 0)
                                                                    {{ $discipline['nameDiscipline'] }}
                                                                    @php
                                                                        $i = 1;
                                                                    @endphp
                                                                @else
                                                                    , {{ $discipline['nameDiscipline'] }}
                                                                @endif
                                                            @endif
                                                        @endforeach
                                                    @endif
                                                @endforeach
                                                .
                                            </p>
                                        </div>
                                        <div class="col-lg-3 mt-3"><a class="btn btn-primary col-10 text-white"
                                                href="{{ route('read.book', $book['id']) }}">Lire</a></div>
                                    </div>
                                    <small class="text-primary">
                                        @if ($book['edition'])
                                            Edition : {{ $book['edition'] }} -
                                        @endif
                                        ISBN : {{ $book['ISBN'] }}
                                    </small>
                                </div>
                            </div>
                        </div>
                    @endforeach
                @endif
            </div>
        </section>

    </main>
    <script src="/js/jquery-3.2.1.min.js"></script>
    <!-- Fenetre modale 1-->

    <div class="modal fade" id="confModal6" tabindex="-1" role="dialog" aria-
        labelledby="confModalLabel6" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 id="confModalLabel6">Souhaitez-vous vraiment ajouter ce livre à la base de données des
                        livres ?</h5>
                    <button type="button" class="close" data-bs-dismiss="modal" aria-
                        label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <div class="card">
                        <div class="card-header">
                            <h4> <a href="#" id="modal-titre1"></a> </h4>
                        </div>

                        <div class="card-body">
                            <small class="text-primary" id="modal-version1">
                            </small>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default"
                        data-bs-dismiss="modal">Annuler</button>
                    <button type="button" class="btn btn-primary"><a
                            class="col-10 text-white" id="lien1"
                            href="#">Ajouter</a></button>
                </div>
            </div>
        </div>
    </div>
    <!-- Fin fenetre modale 1-->
    <script src="/js/popper.min.js"></script>
    <script src="/js/bootstrap.min.js"></script>
    <script src="/js/jquery.magnific-popup.min.js"></script>
    <script src="/js/owl.carousel.min.js"></script>
    <script src="/js/slick.min.js"></script>
    <script src="/js/jquery.meanmenu.min.js"></script>
    <script src="/js/wow.min.js"></script>
    <!-- Counter Script -->
    <script src="/js/waypoints.min.js"></script>
    <script src="/js/jquery.counterup.min.js"></script>
    <script src="/js/custom.js"></script>
@endsection
