<% if (!is_current_site && site.tags_dataset.count > 0) || is_current_site %>
  <h3>Tags</h3>
  <% if is_current_site && site.tags_dataset.count == 0 %>
    <p>You don't have any tags yet. <a href="#addTag" data-toggle="modal">Add some!</a>
  <% else %>
    <% site.tags.each do |tag| %>
      <a class="tag" href="/browse?tag=<%== Rack::Utils.escape tag.name %>"><%= tag.name %></a>
    <% end %>

    <% if is_current_site %>
      <div class="clear">
        <a href="#addTag" data-toggle="modal">Add</a>
        &nbsp;&nbsp;&nbsp;
        <a href="#removeTag" data-toggle="modal">Remove</a>
      </div>
    <% end %>
  <% end %>
<% end %> 

<div class="modal hide fade" id="addTag" tabindex="-1" role="dialog" aria-labelledby="addTagLabel" aria-hidden="true">
  <form method="POST" action="/tags/add">
    <input type="hidden" value="<%= csrf_token %>" name="csrf_token">
    <div class="modal-header">
      <button class="close" type="button" data-dismiss="modal" aria-hidden="true">x</button>
      <h3 id="addTagLabel">Add a Tag</h3>
    </div>
    <div class="modal-body">
      <p>
        A tag can only be a single word, and can only contain letters and numbers.
      </p>
      <p>Tag:</p>
      <input type="text" name="tags" class="typeahead">
    </div>
    <div class="modal-footer">
      <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
      <button type="submit" class="btn btn-Action">Add Tag</button>
    </div>
  </form>
</div>

<div class="modal hide fade" id="removeTag" tabindex="-1" role="dialog" aria-labelledby="removeTagLabel" aria-hidden="true">
  <form method="POST" action="/tags/remove">
    <input type="hidden" value="<%= csrf_token %>" name="csrf_token">
    <div class="modal-header">
      <button class="close" type="button" data-dismiss="modal" aria-hidden="true">x</button>
      <h3 id="removeTagLabel">Remove Tags</h3>
    </div>
    <div class="modal-body">
      <p>
        Select the tags you would like to remove:
      </p>
      <% site.tags.each do |tag| %>
        <input name="tags[]" type="checkbox" value="<%= tag.name %>"> <%= tag.name %>
        <br>
      <% end %>
    </div>
    <div class="modal-footer">
      <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
      <button type="submit" class="btn btn-Action">Remove Tag(s)</button>
    </div>
  </form>
</div>