<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Subscribers</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 active">
                  <a class="nav-link" href="#">Subscribers</a>
                </li>
                <li class="nav-item">
                  <a class="nav-link" href="/book">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 Subscriber</h2>
      <!-- Book insertion form -->
      <form method="post" action="/subscribers">
          <div class="form-group">
              <label for="title">First Name:</label>
              <input type="text" class="form-control" id="title" name="f_name" placeholder="Enter First Name" required>
          </div>
          <div class="form-group">
            <label for="title">Last Name:</label>
            <input type="text" class="form-control" id="title" name="l_name" placeholder="Enter Last Name" required>
        </div>
          <div class="form-group">
              <label for="author">Username:</label>
              <input type="text" class="form-control" id="author" name="username" placeholder="Enter Username" required>
          </div>
          <div class="form-group">
              <label for="genre">Email:</label>
              <input type="text" class="form-control" id="genre" name="email" placeholder="Enter Email" required>
          </div>
          <div class="form-group">
            <label for="genre">Password:</label>
            <input type="password" class="form-control" id="genre" name="password" placeholder="Enter Password" required>
        </div>
        <div class="form-group">
          <label for="genre">Password Again:</label>
          <input type="password" class="form-control" id="genre" name="passwordV" placeholder="Enter Password" required>
      </div>
          <button type="submit" class="btn btn-success">Add Subscriber</button>
      </form>
  </div>

    <div class="container mt-4">
        <div id="submittedInfo">
            <h1>Subscribers</h1>
        
            <% if (clients && clients.length > 0) { %>
                <div class="row">
                    <% clients.forEach((client, index) => { %>
                        <% if (index % 3 === 0 && index !== 0) { %>
                            </div><div class="row">
                        <% } %>
                        <div class="col-md-12">
                            <div class="card mb-3">
                                <div class="card-body">
                                    <h5 class="card-title"><%= client.first_name %> <%= client.last_name %></h5>
                                    <p class="card-text">Email: <%= client.email %></p>
                                    <div class="d-flex justify-content-between">
                                        <form method="POST" action="/delete-subscriber/<%= client.id %>" onsubmit="return confirm('Are you sure you want to delete this clinet?');">
                                            <button type="submit" class="btn btn-danger">Delete</button>
                                        </form>
                                        <form method="POST" action="/edit-subscriber/<%= client.id %>"  onsubmit="return confirm('Are you sure you want to Edit this book?');">
                                            <button type="submit" class="btn btn-warning">Edit</button>
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </div>
                    <% }); %>
                </div>
            <% } else { %>
                <p>No Subscribers available.</p>
            <% } %>
        </div>
    </div>
    


  
    <!-- Add more book cards dynamically here -->
  </div>
  <div class="modal fade" id="errorModal" tabindex="-1" aria-labelledby="errorModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title" id="errorModalLabel">Error</h5>
          <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
        </div>
        <div class="modal-body">
          <div class="alert alert-warning" role="alert">
            <p id="errorMessage"><%= errorMessage %></p>
          </div>
        </div>
      </div>
    </div>
  </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>
      const errorMessage = '<%= errorMessage %>'; // Use the errorMessage variable passed from the server-side code
  
      document.addEventListener('DOMContentLoaded', () => {
          if (errorMessage && errorMessage.trim() !== '') {
              const errorModalBtn = document.getElementById('errorModalBtn');
              errorModalBtn.click();
          }
      });

      if (window.location.href !== 'http://localhost:3000/subscribers') {
            window.location.href = 'http://localhost:3000/subscribers';
        }
  </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>
