@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 collapsed" 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" 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 show" 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>Ajout de livres</h1>
            <nav>
                <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href="{{ url('admin') }}">Accueil</a></li>
                    <li class="breadcrumb-item">Gestion des livres</li>
                    <li class="breadcrumb-item active">Ajout de livre</li>
                </ol>
            </nav>
        </div><!-- End Page Title -->

        <section class="section">
            <div class="row">
                <div class="col-lg-10">
                    <div class="card">
                        <div class="card-body">
                            <h5 class="card-title">Informations sur le nouveau livre </h5>

                            <!-- General Form Elements -->
                            <form method="POST" action="{{ route('update.book',$book->id) }}">
                                @csrf()
                                @method('put')
                                <div class="row mb-3">
                                    <label for="inputText" class="col-sm-2 col-form-label">Titre du livre * </label>
                                    <div class="col-sm-10">
                                        <input type="text" name="titre" value="{{ old('titre',$book->titre) }}"
                                            class="form-control" placeholder="Ex: Apprendre à programmer en C++">
                                    </div>
                                </div>
                                <div class="row mb-3">
                                    <label for="inputText" class="col-sm-2 col-form-label">Nom de l'auteur *</label>
                                    <div class="col-sm-10">
                                        <input type="text" name="auteur" value="{{ old('auteur', $book->auteur) }}"
                                            class="form-control" placeholder="Ex: Claude Delannoy">
                                    </div>
                                </div>
                                <div class="row mb-3">
                                    <label for="inputText" class="col-sm-2 col-form-label">Edition du livre</label>
                                    <div class="col-sm-10">
                                        <input type="text" name="edition" value="{{ old('edition', $book->edition) }}"
                                            class="form-control" placeholder="Ex: DUNOD">
                                    </div>
                                </div>
                                <div class="row mb-3">
                                    <label for="inputText" class="col-sm-2 col-form-label">ISBN *</label>
                                    <div class="col-sm-10">
                                        <input type="number" name="ISBN" class="form-control"
                                            placeholder="Ex: 9782843449499" value="{{ old('ISBN', $book->ISBN) }}">
                                    </div>
                                </div>
                                <div class="row mb-3">
                                    <label for="inputText" class="col-sm-2 col-form-label">Discipline</label>
                                    <div class="col-sm-10">
                                        <select name="discipline[]" class="form-select js-example-basic-multiple" multiple>
                                            @foreach ($discipline as $disp)
                                                <option value="{{ $disp->id }}"
                                                    {{ in_array($disp->id, old('discipline') ?: $book->disciplines->pluck('id')->all()) ? 'selected' : '' }}>
                                                    {{ $disp->nameDiscipline }}
                                                </option>
                                            @endforeach
                                        </select>
                                    </div>
                                </div>
                                <div class="row mb-3">
                                    <label for="inputText" class="col-sm-2 col-form-label">Description sur le livre
                                        *</label>
                                    <div class="col-sm-10">
                                        <textarea type="text" name="description" class="form-control"
                                            placeholder="Ex: Un bon livre qui nous apprends à programmer en langage C++">{{ old('description',$book->description) }}</textarea>
                                    </div>
                                </div>
                                <div class="row mb-4 justify-content-center">
                                    <button type="submit" class="btn btn-primary col-md-3">Sauvegarder</button>
                                </div>

                            </form><!-- End General Form Elements -->

                        </div>
                    </div>

                </div>

        </section>

    </main>
    @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
