<% content_for :title, 'Trash' %>

<% content_for :breadcrumbs do %>
  <ol class="breadcrumb">
    <li class="breadcrumb-item">
      <%= link_to current_project.name, project_path(current_project) %>
    </li>
    <li class="breadcrumb-item active">
      Trash
    </li>
  </ol>
<% end %>

<div class="content-container" id="trash">
  <% if @revisions.any? %>
    <% cache @revisions do %>
      <div class="table-wrapper">
        <table class="table table-striped"
          data-behavior="dradis-datatable"
          data-default-columns='["Item", "Removed by", "When"]'
          data-local-storage-key="project.ce.<%= dom_id(current_project) %>.revisions_datatable">
          <thead>
            <tr>
              <th>Item</th>
              <th>Removed by</th>
              <th>When</th>
              <th class="no-sort" data-column-visible="false"><span class="visually-hidden">Actions</span></th>
            </tr>
          </thead>
          <tbody>
            <% @revisions.each do |recoverable_revision| %>
              <% cache recoverable_revision do %>
                <% present recoverable_revision do |recoverable_revision_presenter| %>
                  <tr>
                    <td><%= recoverable_revision_presenter.info %></td>
                    <td><%= recoverable_revision_presenter.whodunnit %></td>
                    <td data-sort="<%= recoverable_revision.version.created_at.to_i %>"><%= recoverable_revision_presenter.created_at_ago %></td>
                    <td>
                      <%= link_to(
                        recover_project_revision_path(
                          current_project,
                          recoverable_revision.version,
                        ),
                        method: :post,
                        data: { confirm: 'Are you sure?' }
                      ) do %>
                        <i class="fa-solid fa-refresh"></i> Recover
                      <% end %>
                    </td>
                  </tr>
                <% end %>
              <% end %>
            <% end %>
          </tbody>
        </table>
      </div>
    <% end %>
  <% else %>
    The trash is empty.
  <% end %>
</div>
