<%
  content_for :section_title, "Candidates"
  content_for :title, "Candidates - Skills Assessment Admin"
%>

<h1>Candidates</h1>

<%= link_to("Create New Candidate", admin_new_candidate_path, { class: "" }) if policy(Candidate).create? %>

<table cellspacing="0" cellpadding="0">
  <tr>
    <th><%= sortable "name", "Candidate" %></th>
    <th><%= sortable "test_hash", "Test ID" %></th>
    <th><%= sortable "email" %></th>
    <th><%= sortable "experience" %></th>
    <th>Progress</th>
    <th><%= sortable  "completed_at", "Completed" %></th>
    <th><%= sortable "reminded" %></th>
    <th>Interview?</th>
  </tr>

  <% @candidates.each do |candidate| %>
    <tr>
      <td><%= link_to candidate.name, admin_edit_candidate_path(candidate.id) %></td>
      <td><%= candidate.test_hash %></td>
      <td>
        <%= mail_to(candidate.email) %>
        <br />
        <%= link_to "resend welcome email", admin_resend_welcome_path(candidate.id), remote: true, class: '', data: { id: 'ajax-action' } %>
      </td>
      <td><%= candidate.experience %> years</td>
      <td><%= candidate.status %></td>
      <td><%= candidate.completed ? link_to("Submitted", admin_result_path(candidate.test_hash)) : "" %></td>
      <td><%= candidate.reminded ? "Yes" : "" %></td>
      <td><%= candidate.interview? %></td>
    </tr>
  <% end %>
</table>

<%= paginate @candidates %>
