<!DOCTYPE html>
<html lang="it">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" type="text/css" href="/static/style.css">
    <title>Libreria</title>
    <%- include('./partials/navbar'); %>
    <div class="container" id="titleleft">
        <h2>Libreria</h2>
    </div>
</head>
<body>
<div class="container">
        
    <div>
        <h4>Condividi la tua libreria</h4>
        <button type="button" class="btn btn-primary btn-lg" data-bs-toggle="modal" data-bs-target="#shareModal">
            Condividi
        </button>
    </div>
    <div class="modal fade" id="shareModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Condividi la tua libreria</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    Condividi questo <a href="https://mybookset.herokuapp.com/libreria/<%= req.session.logged_in_id %>/condividi/">link</a> 
                    tramite email o messaggio per mostrare la tua libreria digitale
                    <br>
                    Link condivisione: 
                    <input disabled type="text" name="sharelink" id="sharelinktext" value="https://mybookset.herokuapp.com/libreria/<%= req.session.logged_in_id %>/condividi/">
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Chiudi</button>
                </div>
            </div>
        </div>
    </div>

    <% if(errore.length != 0) {%>
        <div class="alert alert-warning alert-dismissible fade show" role="alert">
            <%= errore %>
            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        </div>
    <%}%>

    <% if(libri.length > 0) { %>
    <div class="row" style="padding-top: 30px; padding-left: 10px; padding-right: 10px;">
        <% libri.forEach(libro => { %>
            <div class="col">
                <div class="card" style="width: 18rem;">
                    <img class="card-img-top" src="<%= libro.urlCopertina %>" alt="Card image cap" width="230" height="450">
                    <div class="card-body">
                        <h5 class="card-title">
                            <%= libro.Titolo %>
                        </h5>
                        <h6 class="card-subtitle mb-2 text-muted">
                            <%= libro.Autore %>
                        </h6>

                        <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="<%= '#n' + libro.Isbn %>">
                            Dettagli
                        </button>
                        
                        <div class="modal fade" id="<%= 'n' + libro.Isbn %>" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1"
                            aria-labelledby="staticBackdropLabel" aria-hidden="true">
                            <div class="modal-dialog">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <h5 class="modal-title" id="staticBackdropLabel">
                                            <%= libro.Titolo %>
                                        </h5>
                                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                                    </div>
                                    <div class="modal-body">
                                        <p>
                                            <%= libro.Descrizione %>
                                        </p>
                                        <br>
                                        <dl class="row">
                                            <dt class="col-sm-3">Genere</dt>
                                            <dd class="col-sm-9"><%= libro.Genere %></dd>
                                            <dt class="col-sm-3">Pagine Lette</dt>
                                            <dd class="col-sm-9"><%= libro.PagineLette %> di <%= libro.Pagine %></dd>
                                        
                                            <dt class="col-sm-3">Completato</dt>
                                            <dd class="col-sm-9">
                                                <% if(libro.Completato){%> <p>Si</p> <% }else{ %> <p>No</p> <% } %>
                                            </dd>
                                        
                                            <dt class="col-sm-3">Impressioni</dt>
                                            <dd class="col-sm-9"><% if(libro.Impressioni === ''){%> <p>Ancora niente...</p> <% }else{ %> <%= libro.Impressioni %> <% } %></dd>
                                        
                                            <dt class="col-sm-3">Valutazione</dt>
                                            <dd class="col-sm-9">
                                                <% if(libro.Valutazione == 0){ %>

                                                    <%= libro.Valutazione %> (Non ancora valutato)
                                                <% }else if(libro.Valutazione == 5){ %>
                                                    <%= libro.Valutazione %> (Mi e' piaciuto molto)
                                                <% }else if(libro.Valutazione == 1){ %>
                                                    <%= libro.Valutazione %> (non mi Ã¨ piaciuto)
                                                <% }else{ %>
                                                    <%= libro.Valutazione %>
                                                <% } %>
                                            </dd>
                                        </dl>
                                    </div>
                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Chiudi</button>
                                        <a class="btn btn-primary" href="/libreria/modifica/<%= libro.Isbn %>" role="button">Modifica</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <a class="btn btn-outline-danger" href="/libreria/elimina/<%= libro.Isbn %>">
                            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-trash" viewBox="0 0 16 16">
                                <path
                                    d="M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0V6z" />
                                <path fill-rule="evenodd"
                                    d="M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1v1zM4.118 4 4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4H4.118zM2.5 3V2h11v1h-11z" />
                            </svg>
                            Elimina
                        </a>
                    </div>
                </div>
            </div>
        <% }) %>
    </div>
    <% } else { %>
        <div class="subtitle" id="titlecenter">
            <h2>Ancora nessun libro inserito: <a href="/libreria/aggiungi">vai alla pagina di inserimento</a></h2>
        </div>
    <% } %>
</div>
</body>
</html>