<!DOCTYPE html>
<html lang="en">
  <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
      href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css"
      rel="stylesheet"
      integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ"
      crossorigin="anonymous"
    />
    <title>URL Shortener</title>
  </head>
  <body>
    <div class="container">
      <h1>URL Shortener</h1>
      <form action="/shorturls" method="POST" class="my-4 forminline">
        <label for="fullUrl" class="visually-hidden">URL</label>
        <div class="input-group mb-3">
          <input
            placeholder="URL"
            type="url"
            name="fullUrl"
            id="fullUrl"
            class="form-control col mr-2"
          />
          <button class="btn btn-success" type="submit">Shrink</button>
        </div>
      </form>

      <table
        class="table align-middle table-striped table-hover table-responsive table-bordered border-secondary table-sm"
      >
        <thead class="table-dark">
          <tr>
            <th>Full URL</th>
            <th>Short URL</th>
            <th>Clicks</th>
            <th>Delete URL</th>
          </tr>
        </thead>
        <tbody>
          <% shorturls.forEach(shorturl => { %>
          <tr>
            <td><a href="<%= shorturl.full %>"><%= shorturl.full %></a></td>
            <td><a href="<%= shorturl.short %>"><%= shorturl.short %></a></td>
            <td><%= shorturl.clicks %></td>
            <td>
              <form method="POST" action="/<%= shorturl._id %>">
                <input type="hidden" name="_method" value="DELETE" />
                <button class="btn btn-danger" type="submit">Delete</button>
              </form>
            </td>
          </tr>
          <% }) %>
        </tbody>
      </table>
    </div>
  </body>
</html>
