<%- include('../partials/header', { title }) %>

<div class="admin-page-head">
  <div>
    <h2>Job Applications</h2>
    <p style="color: var(--ink-300);"><%= applications.length %> submissions</p>
  </div>
</div>

<div class="table-wrap">
  <table class="data-table">
    <thead><tr><th>Applicant</th><th>Applied For</th><th>Resume</th><th>Status</th><th>Submitted</th><th></th></tr></thead>
    <tbody>
      <% if (!applications.length) { %>
        <tr><td class="empty-row" colspan="6">No applications yet.</td></tr>
      <% } %>
      <% applications.forEach(function(a) { %>
        <tr>
          <td class="cell-title"><%= a.full_name %><br /><span style="font-size:0.75rem; color: var(--ink-300);"><%= a.email %></span></td>
          <td class="cell-muted"><%= a.job_title || '—' %></td>
          <td class="cell-muted"><a href="<%= a.resume_path %>" target="_blank">View resume</a></td>
          <td>
            <form action="/admin/applications/jobs/<%= a.id %>/status" method="POST" data-status-form>
              <input type="hidden" name="_csrf" value="<%= csrfToken %>" />
              <select name="status" class="status-select">
                <% statuses.forEach(function(s) { %>
                  <option value="<%= s %>" <%= a.status === s ? 'selected' : '' %>><%= s %></option>
                <% }); %>
              </select>
            </form>
          </td>
          <td class="cell-muted"><%= new Date(a.created_at).toLocaleDateString('en-US') %></td>
          <td class="actions">
            <form action="/admin/applications/jobs/<%= a.id %>/delete" method="POST" data-confirm="Remove this application?">
              <input type="hidden" name="_csrf" value="<%= csrfToken %>" />
              <button class="icon-btn is-danger" type="submit" title="Delete"><i data-lucide="trash-2" width="15" height="15"></i></button>
            </form>
          </td>
        </tr>
      <% }); %>
    </tbody>
  </table>
</div>

<%- include('../partials/footer') %>
