<% is_processed = params[:status].to_s != 'pending' %>
<table class="table table-hover text-center job-authentication-list-table">
  <thead class="thead-light">
  <tr>
    <th width="4%">序号</th>
    <th width="8%">头像</th>
    <th width="18%">创建者</th>
    <th width="14%">单位</th>
    <th width="24%">发布时间</th>
    <th width="16%">职位查看</th>
    <% if !is_processed %>
      <th width="16%">操作</th>
    <% else %>
      <th width="16%">审批结果</th>
    <% end %>
  </tr>
  </thead>
  <tbody>
  <% if jobs.present? %>
    <% jobs.each_with_index do |job, index| %>
      <tr class="job-authentication-item job-authentication-<%= job.id %>">
        <td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
        <td>
          <%= link_to "/users/#{job.user.login}", class: 'job-authentication-avatar', target: '_blank', data: { toggle: 'tooltip', title: '个人主页' } do %>
            <img src="/images/<%= url_to_avatar(job.user) %>" class="rounded-circle" width="40" height="40" />
          <% end %>
        </td>
        <td><%= job.user.real_name %></td>
        <td><%= raw [job.user.school_name.presence, job.user.department_name.presence].compact.join('<br/>') %></td>
        <td><%= job.updated_at.strftime('%Y-%m-%d %H:%M') %></td>
        <td>
          <%= link_to job.name, admins_job_authentication_path(job), remote: true, id: "item_name_#{index}", class: "d-inline-block text-truncate" %>
        </td>
        <td class="action-container">
          <% if !is_processed %>
            <%= agree_link '同意', agree_admins_job_authentication_path(job, element: ".job-authentication-#{job.id}"), 'data-confirm': '确认同意该审批？', 'data-disable-with': "提交中..." %>
            <%= link_to '拒绝', "javascript:;", id: "#{job.id}", class: "action reject" %>
          <% else %>
            <%= job.apply_action.status_text %>
            <% if job.state == 'published' %>
              <%= link_to '拒绝', "javascript:;", id: "#{job.id}", class: "action reject" %>
            <% end %>
          <% end %>
        </td>
      </tr>
    <% end %>
  <% else %>
    <%= render 'admins/shared/no_data_for_table' %>
  <% end %>
  </tbody>
</table>

<%= render partial: 'admins/shared/paginate', locals: { objects: jobs } %>