<h1>Blocked Script Codes</h1>

<p>If a script's code contains any of these patterns the script save will be rejected, or it will be deleted and the author banned.</p>

<% if current_user.administrator? %>
  <p><%= link_to 'Add new', new_admin_blocked_script_code_path %></p>
<% end %>

<table class="blocked-script-codes">
    <% current_category = 'something' %>
    <% @blocked_script_codes.each do |blocked_script_code| %>
      <thead>
        <% if current_category != blocked_script_code.category %>
          <tr>
            <th colspan="6">
              <h3>
                <%= blocked_script_code.category&.capitalize || '(Uncategorized)' %>
              </h3>
            </th>
          </tr>
          <% current_category = blocked_script_code.category %>
        <tr>
          <th></th>
          <th>Public Reason</th>
          <th>Private Reason</th>
          <th>Result</th>
          <th>Originating Script</th>
          <th></th>
        </tr>
      </thead>
    <% end %>
    <tbody>
      <tr class="pattern-row">
        <td colspan="6">
          <code><%= blocked_script_code.pattern %></code>
          <% if blocked_script_code.case_insensitive %>
            <b><i>(Case insensitive)</i></b>
          <% end %>
        </td>
      </tr>
      <tr class="info-row">
        <td></td>
        <td><%= blocked_script_code.public_reason %></td>
        <td><%= blocked_script_code.private_reason %></td>
        <td><%= blocked_script_code.result.capitalize %></td>
        <td><%= link_to(blocked_script_code.originating_script.default_name, blocked_script_code.originating_script) if blocked_script_code.originating_script %></td>
        <td>
          <%= link_to('Edit', edit_admin_blocked_script_code_path(blocked_script_code)) if current_user.administrator? %>
          <%= link_to('Delete', admin_blocked_script_code_path(blocked_script_code), data: { turbo: true, turbo_method: :DELETE}) if current_user.administrator? %>
        </td>
      </tr>
    <% end %>
  </tbody>
</table>
