<% is_processed = params[:status].to_s != 'pending' %>

<table class="table table-hover text-center identity-authentication-list-table">
  <thead class="thead-light">
  <tr>
    <th width="8%">头像</th>
    <th width="10%">姓名</th>
    <th width="14%">身份证号</th>
    <th width="20%">学校/单位</th>
    <th width="12%">职称</th>
    <% unless is_processed %>
      <th width="8%">
        照片
        <i class="fa fa-question-circle" data-toggle="tooltip" data-html="true" data-placement="top" title="审核完成后自动删除图片"></i>
      </th>
    <% end %>
    <th width="16%">时间</th>
    <% if is_processed %>
      <th width="14%">拒绝原因</th>
      <th width="8%">状态</th>
    <% else %>
      <th width="20%">操作</th>
    <% end %>
  </tr>
  </thead>
  <tbody>
  <% if applies.present? %>
    <% applies.each do |apply| %>
      <% user = apply.user %>
      <tr class="identity-authentication-item identity-authentication-<%= apply.id %>">
        <td>
          <%= link_to "/users/#{user.login}", class: 'identity-authentication-avatar', target: '_blank', data: { toggle: 'tooltip', title: '个人主页' } do %>
            <img src="/images/<%= url_to_avatar(user) %>" class="rounded-circle" width="40" height="40" />
          <% end %>
        </td>
        <td><%= user.real_name %></td>
        <td><%= user.ID_number %></td>
        <td><%= raw [user.school_name.presence, user.department_name.presence].compact.join('<br/>') %></td>
        <td><%= user.identity %> <%= raw user.user_extension.student? && user.student_id ? "<br/>#{user.student_id}" : '' %></td>

        <% unless is_processed %>
          <td>
            <% if File.exists?(disk_real_name_auth_filename(user.id)) %>
              <%= image_tag(real_name_auth_file_url(user.id).to_s + "?#{Time.now.to_i}", width: 40, height: 40, class: 'preview-image auth-image', data: { toggle: 'tooltip', title: '点击预览' }) %>
            <% else %>
              <%= content_tag(:span, '图片已删除', class: 'text-secondary') %>
            <% end %>
          </td>
        <% end %>

        <td><%= apply.updated_at.strftime('%Y-%m-%d %H:%M') %></td>

        <% if is_processed %>
          <td class="text-secondary"><%= overflow_hidden_span apply.remarks, width: 140 %></td>
          <td><span class="apply-status-<%= apply.status %>"><%= apply.status_text %></span></td>
        <% else %>
          <td class="action-container">
            <%= agree_link '同意', agree_admins_identity_authentication_path(apply, element: ".identity-authentication-#{apply.id}"), 'data-confirm': '确认审核通过？' %>
            <%= javascript_void_link('拒绝', class: 'action refuse-action',
                                     data: {
                                         toggle: 'modal', target: '.admin-common-refuse-modal', id: apply.id,
                                         url: refuse_admins_identity_authentication_path(apply, element: ".identity-authentication-#{apply.id}")
                                     }) %>
          </td>
        <% end %>
      </tr>
    <% end %>
  <% else %>
    <%= render 'admins/shared/no_data_for_table' %>
  <% end %>
  </tbody>
</table>

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