<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Library</title>
    <!-- Bootstrap CSS -->
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/js/bootstrap.bundle.min.js"></script>
    <link href="/docs/5.2/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" integrity="sha512-KfkfwYDsLkIlwQp6LFnl8zNdLGxu9YAA1QvwINks4PhcElQSvqcyVLLD9aMhXd13uQjoXtEKNosOWaZqXgel0g==" crossorigin="anonymous" referrerpolicy="no-referrer" />

    <style>
        /* Additional CSS styles */
        .book-container {
            display: flex;
            flex-wrap: wrap;
            justify-content: space-around;
            margin-top: 20px;
        }
        .book-card {
            width: 200px;
            margin-bottom: 20px;
            border: 1px solid #ccc;
            border-radius: 5px;
            padding: 10px;
        }
        /* Other styles as needed */
    </style>
</head>
<body>
    <header>
        <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo03" aria-controls="navbarTogglerDemo03" aria-expanded="false" aria-label="Toggle navigation">
              <span class="navbar-toggler-icon"></span>
            </button>
            <a class="navbar-brand" href="/admin">DigitalLibrary</a>
          
            <div class="collapse navbar-collapse" id="navbarTogglerDemo03">
              <ul class="navbar-nav mr-auto mt-2 mt-lg-0">
                <li class="nav-item">
                  <a class="nav-link" href="subscribers">Subscribers</a>
                </li>
                <li class="nav-item active">
                  <a class="nav-link" href="#">Books</a>
                </li>
              </ul>
              <ul class="navbar-nav">
                <li class="nav-item">
                    <a class="nav-link" href="/logout">Logout</a>
                </li>
            </ul>
            </div>
          </nav>
      </header>
    <!-- Navigation Bar with Logout -->

    <!-- Search Bar -->

    <div class="container mt-4">
        <h2>Add Book</h2>
        <!-- Book insertion form -->
        <form method="post" action="/book">
            <div class="form-group">
                <label for="title">Book Title:</label>
                <input type="text" class="form-control" id="title" name="bookName" placeholder="Enter Book Title" required>
            </div>
            <div class="form-group">
                <label for="author">Author Name:</label>
                <input type="text" class="form-control" id="author" name="authorName" placeholder="Enter Author Name" required>
            </div>
            <div class="form-group">
                <label for="genre">Genre Type:</label>
                <input type="text" class="form-control" id="genre" name="genre" placeholder="Enter Genre Type" required>
            </div>
            <div class="form-group">
                <label for="quantity">Available Quantity:</label>
                <input type="number" class="form-control" id="quantity" name="numAvailable" placeholder="Enter Quantity Available" required>
            </div>
            <button type="submit" class="btn btn-success">Add Book</button>
        </form>
    </div>

<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 bg-danger text-white">
                <h5 class="modal-title" id="deleteModalLabel">Confirm Delete</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            
            <div class="modal-body">
                <p>Are you sure you want to delete this book?</p>
            </div>
            
            <form id="deleteForm" method="POST" action="/delete-book/">
                <input type="hidden" id="bookId" name="bookId">
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
                    <button type="submit" class="btn btn-danger" id="confirmDeleteBtn">Delete</button>
                </div>
            </form>
        </div>
    </div>
</div>




<!-- Modal for confirming remove one book -->
<div class="modal fade" id="removeOneBookModal" tabindex="-1" aria-labelledby="removeOneBookModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header bg-warning text-white">
                <h5 class="modal-title" id="removeOneBookModalLabel">Confirm Remove One Book</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <p>Are you sure you want to remove one book?</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
                <button type="button" class="btn btn-warning" id="confirmRemoveOneBtn">Remove One Book</button>
            </div>
        </div>
    </div>
</div>

<!-- <% books.forEach((book, index)=> { %>
    <div class="col-md-12">
        <div class="card mb-3">
            <div class="card-body">
                <strong>Title:</strong> <%= book.book_name %><br>
                <strong>Author:</strong> <%= book.author %><br>
                <strong>Genre:</strong> <%= book.genre %><br>
                <strong>Available Quantity:</strong> <%= book.num_available %><br><br>
                <div class="d-flex justify-content-between">
                    <div class="d-flex justify-content-between">
                        <div>
                            <button type="button" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#deleteModal" >
                                Delete
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
<% }); %> -->

<!-- Modal for confirming delete -->
<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 bg-danger text-white">
                <h5 class="modal-title" id="deleteModalLabel">Confirm Delete</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <p>Are you sure you want to delete this book?</p>
            </div>
            <!-- Form to submit book deletion -->
            <form method="POST" action="/delete-book/" id="deleteBookForm">
                <input type="hidden" id="bookIDInput" name="bookId">
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
                    <button type="submit" class="btn btn-danger">Delete</button>
                </div>
            </form>
        </div>
    </div>
</div>



<div class="container mt-4">
    <div id="submittedInfo">
        <h1>Books</h1>
        <% books.forEach((book, index) => { %>
            <div class="col-md-12">
                <div class="card mb-3">
                    <div class="card-body">
                        <strong>Title:</strong> <%= book.book_name %><br>
                        <strong>Author:</strong> <%= book.author %><br>
                        <strong>Genre:</strong> <%= book.genre %><br>
                        <strong>Available Quantity:</strong> <%= book.num_available %><br><br>
                        <div class="d-flex justify-content-between">
                            <div class="d-flex justify-content-between">
                                <div>
                                    <form method="POST" action="/delete-book/<%= book.id %>" onsubmit="return confirm('Are you sure you want to delete this book?');">
                                        <button type="submit" class="btn btn-danger">Delete</button>
                                    </form>
                                    <!-- <button type="button" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#deleteModal" >
                                        Delete
                                    </button> -->
                                </div>
                            </div>

                            <div>
                                <button type="button" class="btn btn-warning" data-bs-toggle="modal" data-bs-target="#removeOneBookModal">
                                    Remove One
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
           
        <% }); %>
    </div>
</div>



  
    <!-- Add more book cards dynamically here -->
  </div>
    <footer class="footer d-flex justify-content-center align-items-center mt-auto text-dark-50">
        <a
         class="btn btn-link btn-floating btn-lg text-dark m-1"
         href="#!"
         role="button"
         data-mdb-ripple-color="dark"
         ><i class="fab fa-facebook-f"></i
       ></a>
       <a
         class="btn btn-link btn-floating btn-lg text-dark m-1"
         href="#!"
         role="button"
         data-mdb-ripple-color="dark"
         ><i class="fab fa-twitter"></i
       ></a>
        <a
          class="btn btn-link btn-floating btn-lg text-dark m-1"
          href="#!"
          role="button"
          data-mdb-ripple-color="dark"
          ><i class="fab fa-instagram"></i>
        </a>
        <a
            class="btn btn-link btn-floating btn-lg text-dark m-1"
            href="https://github.com/MrBrown23/"
            role="button"
            data-mdb-ripple-color="dark"
            ><i class="fa-brands fa-github"></i>
        </a>
        <div class="mt-3">
          <p class="text-dark">Copyright &copy; 2024 <a href="/admin" class="text-dark">DigitalLibrary</a>.</p>
        </div>
      </footer>

    <!-- Bootstrap JS -->
    <script>
        let bookID=0;
        function setBookId(id) {
        alert(id);
        bookID = id; // Set the bookId value to the input field
}

    </script>
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.5/dist/umd/popper.min.js"></script>
      <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/js/bootstrap.min.js"></script>
</body>
</html>
