<table class="table table-striped mb-0"
  data-behavior="dradis-datatable"
  data-default-columns="<%= @default_columns.to_json %>"
  data-item-name=<%= "issue_#{@issue.id}_evidence" %>
  data-local-storage-key="project.ce.<%= dom_id(current_project) %>.<%= "issue_#{@issue.id}_evidence_datatable" %>"
  >
  <thead>
    <tr>
      <th class="no-sort" data-column-visible="false"><span class="visually-hidden">Select</span></th>
      <% @all_columns.each do |column| %>
        <th><%= column %></th>
      <% end %>
      <th class="no-sort" data-column-visible="false"><span class="visually-hidden">Actions</span></th>
    </tr>
  </thead>
  <tbody>
    <% @affected_nodes.each do |node| %>
      <% node.evidence.where(issue_id: @issue.id).each do |evidence| %>
        <tr id="evidence-<%= evidence.id %>">
          <td class="select-checkbox" data-behavior="select-checkbox"></td>
          <% @all_columns.each do |column| %>
            <%
              sort, display =
              case column
              when 'Label'
                [evidence.node.label, link_to(evidence.node.label, [current_project, node, evidence])]
              when 'Created'
                [evidence.created_at.to_i, local_time_ago(evidence.created_at)]
              when 'Created by'
                [evidence.author, evidence.author]
              when 'Updated'
                [evidence.updated_at.to_i, local_time_ago(evidence.updated_at)]
              else
                [evidence.fields.fetch(column, ''), markup(evidence.fields.fetch(column, ''))]
              end
            %>
            <td data-sort="<%= sort %>"><%= display %></td>
          <% end  %>
          <td class="column-actions">
            <%= link_to edit_project_node_evidence_path(current_project, node, evidence, return_to: :issue) do %>
              <i class="fa-solid fa-pencil"></i> Edit
            <% end %>
            <%= link_to [current_project, node, evidence],
                  class: 'text-error-hover',
                  data: { confirm: "Are you sure?\n\nProceeding will delete this evidence from the associated node." },
                  method: :delete do %>
              <i class="fa-solid fa-trash"></i> Delete
            <% end %>
          </td>
        </tr>
      <% end %>
    <% end %>
  </tbody>
</table>
