<% provide :title, t('.title') %>
<div style="margin-bottom: 1em;">
  <%= form_tag({:action => "index"}, :method => :get) do %>
    <%= text_field_tag "query", params[:query] %>
    <%= submit_tag t('.search') %>
    <%= submit_tag t('tag_alias.index.search') %>
  <% end %>
</div>

<%= form_tag(:action => "update") do %>
  <table class="highlightable" width="100%">
    <thead>
      <tr>
        <th width="1%"></th>
        <th width="19%"><%= t('.predicate') %></th>
        <th width="20%"><%= t('.consequent') %></th>
        <th width="60%"><%= t('.reason') %></th>
      </tr>
    </thead>
    <tfoot>
      <tr>
        <td colspan="4">
          <% if @current_user.is_mod_or_higher? %>
            <%= button_tag t(".select_pending"), :type => "button", :class => "js-check_all", :data => { :target => "tag-implications" } %>
            <%= submit_tag t('.approve') %>
          <% end %>
          <%= button_to_function t('.delete'), "$('reason-box').show(); $('reason').focus()" %>
          <%= button_to_function t('.add'), "$('add-box').show().scrollTo(); $('tag_implication_predicate').focus()" %>

          <div id="reason-box" style="display: none; margin-top: 1em;">
            <strong><%= t('.reason') %>:</strong>
            <%= text_field_tag "reason", "", :size => 40 %>
            <%= submit_tag t('.delete') %>
          </div>
        </td>
      </tr>
    </tfoot>
    <tbody>
      <% @implications.each do |i| %>
        <tr class="<%= cycle 'even', 'odd' %> <%= i.is_pending? ? 'pending-tag' : nil %>">
          <td>
            <input
              type="checkbox"
              value="1"
              name="implications[<%= i.id %>]"
              data-target="tag-implications"
              class="<%= "js-check_all-target pending" if i.is_pending? %>"
            >
          </td>
          <td><%= link_to h(i.predicate.name), :controller => "post", :action => "index", :tags => i.predicate.name %> (<%= i.predicate.post_count %>)</td>
          <td><%= link_to h(i.consequent.name), :controller => "post", :action => "index", :tags => i.consequent.name %> (<%= i.consequent.post_count %>)</td>
          <td><%= h i.reason %></td>
        </tr>
      <% end %>
    </tbody>
  </table>
<% end %>

<div id="add-box" style="display: none;">
  <%= form_tag(:action => "create") do %>
    <h4><%= t('.add_new.title') %></h4>
    <p><%= t('.add_new.info_moderation') %></p>
    <p><%= t('.add_new.info') %></p>
    <% unless @current_user.is_anonymous? %>
      <%= hidden_field_tag "tag_implication[creator_id]", @current_user.id %>
    <% end %>

    <table>
      <tr>
        <th><label for="tag_implication_predicate"><%= t('.predicate') %></label></th>
        <td><%= text_field "tag_implication", "predicate", :size => 40 %></td>
      </tr>
      <tr>
        <th><label for="tag_implication_consequent"><%= t('.consequent') %></label></th>
        <td><%= text_field "tag_implication", "consequent", :size => 40 %></td>
      </tr>
      <tr>
        <th><label for="tag_implication_reason"><%= t('.reason') %></label></th>
        <td><%= text_area "tag_implication", "reason", :size => "40x2" %></td>
      </tr>
      <tr>
        <td colspan="2"><%= submit_tag t('.add_new.submit') %></td>
      </tr>
    </table>
  <% end %>
</div>

<div id="paginator">
  <%= will_paginate(@implications) %>
</div>

<%= render :partial => "/tag/footer" %>
