<div class="container">
  <form action ="/register" method="post">
    <div class="form-group">
      <label for="exampleInputEmail1">Email address</label>
      <% try { %>
        <% register.warning %>
          <input type="email" class="form-control" id="emailInput" aria-describedby="emailHelp" placeholder="Enter email" name="email" value=<%= register.email %>>
        <% } catch { %>
          <input type="email" class="form-control" id="emailInput" aria-describedby="emailHelp" placeholder="Enter email" name="email" value=<%= email %>>
      <% } %>
        <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
      <% try { %>
        <% if (register.warning == "registered") { %>
          <small id="usernameMessage" class="form-text text-danger">Email is already registered. <a href="/login">Click here to login</a></small>
        <% } else if (register.warning == "noEmail") { %>
          <small id="passwordMessage" class="form-text text-danger">Please enter an email.</small>
        <% } %>
      <% } catch {} %>
    </div>
    <div class="form-group">
      <label for="exampleInputEmail1">Username</label>
      <% try { %>
        <%  if (register.warning == "noPassword" || register.warning == "badPassword") { %>
          <input type="text" class="form-control" id="usernameInput" placeholder="Enter username" name="username" value=<%= register.username %>>
        <% } else if (register.warning == "noUsername") { %>
          <input type="text" class="form-control" id="usernameInput" placeholder="Enter username" name="username">
          <small id="passwordMessage" class="form-text text-danger">Please enter a username.</small>
        <% } else { %>
          <input type="text" class="form-control" id="usernameInput" placeholder="Enter username" name="username">
        <% } %>
      <% } catch { %>
        <input type="text" class="form-control" id="usernameInput" placeholder="Enter username" name="username">
      <% } %>

    </div>
    <div class="form-group">
      <label for="exampleInputPassword1">Password</label>
      <input type="password" class="form-control" id="inputPassword" placeholder="Password" name="password">
      <% try { %>
        <% if (register.warning == "badPassword") { %>
          <small id="passwordMessage" class="form-text text-danger">Password does not match confirmation.</small>
        <% } else if (register.warning == "noPassword") { %>
          <small id="passwordMessage" class="form-text text-danger">Please enter a password.</small>
        <% } %>
      <% } catch {} %>
    </div>
    <div class="form-group">
      <label for="exampleInputPassword1">Confirm Password</label>
      <input type="password" class="form-control" id="inputConfirmation" placeholder="Re-enter Password" name="confirmation">
      <% try { %>
        <% if (register.warning == "badPassword") { %>
          <small id="passwordMessage" class="form-text text-danger">Password does not match confirmation.</small>
        <% } else if (register.warning == "noPassword") { %>
          <small id="passwordMessage" class="form-text text-danger">Please re-enter password.</small>
        <% } %>
      <% } catch {} %>
    </div>
    <button type="submit" class="btn btn-primary">Submit</button>
  </form>
</div>
