<h1>Manage keys</h1>

<% if @key %>
  <div id='key-info' class="alert alert-info">
  <p>
  New key "<em><%= @key.description %></em>" created:
  </p>
  <pre id='key'><%= @key.key %></pre>
  <p>
  Please copy it now and store it in a safe location.
  <em>It will not be displayed again</em>
  </p>
  </div>
<% end %>

<table class='table table-striped'>
  <tr>
    <td>Description</td>
    <td>Creation date</td>
    <td>Actions</td>
  </tr>
  <% @keys.each do |key| %>
    <tr>
      <td><% if key.description %><%= key.description %> <% else %><em>(none)</em><% end %></td>
      <td><%= key.created_at%></td>
      <td>
        <form method="POST">
          <input name="_method" type="hidden" value="delete" />
          <input name="id" type="hidden" value="<%= key.id %>"/>
          <input class="btn btn-secondary" type='submit' value='Delete'/>
        </form>
      </td>
    </tr>
  <% end %>
</table>

<h2>Create new API key</h2>

<form method="POST" class="row">
  <div class="col-lg-4">
    <input class="form-control" type="text" name="description" placeholder="Key description"/>
  </div>
  <div class="col-lg-2">
    <input class="btn btn-primary" type='submit' value='Create key'/>
  </div>
</form>
