<%- title t('layouts.application.moderator_log') %>
<%- description 'List of actions taken by moderators' %>

<table class="text-content log-table">
  <thead>
    <tr>
      <th><%= t('moderator_logs.date_column') %></th>
      <th><%= t('moderator_logs.moderator_column') %></th>
      <th><%= t('moderator_logs.item_column') %></th>
      <th><%= t('moderator_logs.action_column') %></th>
      <th><%= t('moderator_logs.reason_column') %></th>
    </tr>
  </thead>
  <% @actions.each do |action| %>
    <tr>
      <td><%= markup_date action.created_at %></td>
      <td>
        <% if action.automod %>
          <% if current_user&.moderator? %>
            (Auto)
          <% else %>
            <%= render_user User.administrators.first, User.administrators.first.id, skip_badge: true %>
          <% end %>
        <% else %>
          <%= render_user action.moderator, action.moderator_id, skip_badge: true %>
        <% end %>
      </td>
      <td>
        <% if action.script %>
          <%= t('moderator_logs.item_script_html', script_link: link_to(action.script.name(request_locale), action.script)) %>
        <% elsif action.script_id %>
          <%= t('moderator_logs.item_deleted_script', id: action.script_id) %>
        <% elsif action.user_id %>
          <%= t('moderator_logs.item_user_html', user_link: render_user(action.user, action.user_id, skip_badge: true)) %>
        <% elsif action.discussion %>
          <%= t('moderator_logs.item_discussion_html', discussion_link: (action.discussion.soft_deleted? && !current_user&.moderator?) ? action.discussion.display_title(locale: request_locale) : link_to(action.discussion.display_title(locale: request_locale), action.discussion.path)) %>
        <% elsif action.comment %>
          <%= t('moderator_logs.item_comment_html', comment_link: (action.comment.discussion.soft_deleted? && !current_user&.moderator?) ? action.comment.discussion.display_title(locale: request_locale) : link_to(action.comment.discussion.display_title(locale: request_locale), action.comment.path)) %>
        <% end %>
      </td>
      <td><%= action.action_taken_display(locale: I18n.locale) %></td>
      <td>
        <div class="possibly-long-text">
          <% if action.report %>
            <%= it('moderator_logs.item_report', report_id: action.report_id, report_link: report_path(action.report)) %>
          <% end %>
          <% if !action.script_lock_appeal.nil? %>
            <%= it('moderator_logs.item_script_lock_appeal', appeal_id: action.script_lock_appeal_id, appeal_link: script_script_lock_appeal_path(action.script_lock_appeal.script, action.script_lock_appeal)) %>
          <% end %>
          <%= action.reason %>
        </div>
        <% if current_user&.moderator? && action.private_reason %>
          <div class="possibly-long-text"><%= action.private_reason %></div>
        <% end %>
      </td>
    </tr>
  <% end %>
</table>

<%= render_pagination %>
