<div id="c-meta-searches">
  <div id="a-tags">
    <h1>MetaSearch Tags</h1>

    <section>
      <%= form_tag(meta_searches_tags_path, :method => :get) do %>
        <%= text_field_tag "name", params[:name], :data => { :autocomplete => "tag" } %>
        <%= submit_tag "Go" %>
      <% end %>
    </section>

    <section>
      <h2>Tags</h2>

      <% if @meta_search.tags.empty? %>
        <p>No results</p>
      <% else %>
        <table width="100%" class="striped">
          <thead>
            <tr>
              <th>Name</th>
              <th>Count</th>
              <th></th>
            </tr>
          </thead>

          <tbody>
            <% @meta_search.tags.each do |tag| %>
              <tr>
                <td><%= tag.name %></td>
                <td><%= tag.post_count %></td>
                <td>
                  <% if tag.editable_by?(CurrentUser.user) %>
                    <%= link_to "edit", edit_tag_path(tag) %>
                  <% end %>
                  <% if CurrentUser.is_builder? %>
                    | <%= link_to "fix", new_tag_correction_path(:tag_id => tag.id) %>
                  <% end %>
                </td>
              </tr>
            <% end %>
          </tbody>
        </table>
      <% end %>
    </section>


    <section>
      <h2>Tag Aliases</h2>
      <% if @meta_search.tag_aliases.empty? %>
        <p>No results</p>
      <% else %>
        <table width="100%" class="striped">
          <thead>
            <tr>
              <th>From</th>
              <th>To</th>
              <th></th>
            </tr>
          </thead>

          <tbody>
            <% @meta_search.tag_aliases.each do |tag_alias| %>
              <tr>
                <td><%= tag_alias.antecedent_name %></td>
                <td><%= tag_alias.consequent_name %></td>
                <td>
                  <%= link_to "Show", tag_alias_path(tag_alias) %>
                  <% if tag_alias.deletable_by?(CurrentUser.user) %>
                    | <%= link_to "Delete", tag_alias_path(tag_alias), :remote => true, :method => :delete, :data => {:confirm => "Are you sure you want to delete this alias?"} %>
                  <% end %>

                  <% if CurrentUser.is_admin? && tag_alias.is_pending? %>
                    | <%= link_to "Approve", approve_tag_alias_path(tag_alias), :remote => true, :method => :post %>
                  <% end %>

                  <% if CurrentUser.is_builder? %>
                    | <%= link_to "Fix", tag_alias_correction_path(:tag_alias_id => tag_alias.id) %>
                  <% end %>
                </td>
              </tr>
            <% end %>
          </tbody>
        </table>
      <% end %>
    </section>

    <section>
      <h2>Tag Implications</h2>
      <% if @meta_search.tag_implications.empty? %>
        <p>No results</p>
      <% else %>
        <table width="100%" class="striped">
          <thead>
            <tr>
              <th>From</th>
              <th>To</th>
              <th></th>
            </tr>
          </thead>

          <tbody>
            <% @meta_search.tag_implications.each do |tag_implication| %>
              <tr>
                <td><%= tag_implication.antecedent_name %></td>
                <td><%= tag_implication.consequent_name %></td>
                <td>
                  <%= link_to "Show", tag_implication_path(tag_implication) %>
                  <% if tag_implication.deletable_by?(CurrentUser.user) %>
                    | <%= link_to "Delete", tag_implication_path(tag_implication), :remote => true, :method => :delete, :data => {:confirm => "Are you sure you want to delete this implication?"} %>
                  <% end %>
                  <% if CurrentUser.user.is_admin? && tag_implication.is_pending? %>
                    | <%= link_to "Approve", approve_tag_implication_path(tag_implication), :remote => true, :method => :post %>
                  <% end %>
                </td>
              </tr>
            <% end %>
          </tbody>
        </table>
      <% end %>
    </section>
  </div>
</div>

<%= render "tags/secondary_links" %>

<% content_for(:page_title) do %>
  MetaSearch - Tags - <%= Danbooru.config.app_name %>
<% end %>
