<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

  <!-- Bootstrap CSS -->
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
  <title>miniURL - a TinyApp</title>
</head>
<body>
  <% include ./_header %>
  <main>
    <h2>My URLs</h2>
    <table class="table">
      <thead>
        <tr>
          <th scope="col">Short URL</th>
          <th scope="col">Long URL</th>
          <th scope="col">Last Updated</th>
          <th scope="col">Remove</th>
          <th scope="col">Update</th>
        </tr>
      </thead>
      <tbody>
        <% if (typeof(urls) !== "undefined") {
            for(let url in urls) { %>
          <tr>
            <td><a href="/u/<%= url %>">u/<%= url %></a>  - <%= urls[url].visits %> visits</td>
            <td><a href="<%= urls[url] %>"><%= urls[url].longURL %></a></td>
            <td><%= new Date(urls[url].lastUpdated) %></td>
            <td>
              <form method="POST" action="/urls/<%= url %>/delete">
                <button  type="submit" class="btn btn-outline-danger"> DELETE </button>
              </form>
            </td>
            <td><a href="/urls/<%= url %>"><span class="btn btn-outline-info">Update</span></a></td>
          </tr>
        <% }
        } %>
      </tbody>
    </table>
  </main>
  <% if(typeof(session_id) === "undefined") { %> <h1 style="text-align: center; color:green; margin: 3em auto 3em auto">Please Login First </h1> <%} %>
  <!-- Bootstrap JS -->
  <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>