<% 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="4%">序号</th>
    <% unless is_processed %>
      <th width="4%">
        <%= check_box_tag('all-check', 1, false, id: nil, class: 'batch-all-check-box',
                          data: { toggle: 'tooltip', title: '全选' }) %>
      </th>
    <% end %>
    <th width="8%">头像</th>
    <th width="10%">姓名</th>
    <th width="14%">身份证号</th>
    <th width="20%">学校/单位</th>
    <th width="8%">职称</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 %>
    <% if is_processed %>
      <th width="10%">时间</th>
      <th width="12%">拒绝原因</th>
      <th width="8%">状态</th>
      <th width="8%">操作</th>
    <% else %>
      <th width="16%">时间</th>
      <th width="16%">操作</th>
    <% end %>
  </tr>
  </thead>
  <tbody>
  <% if applies.present? %>
    <% applies.each_with_index do |apply, index| %>
      <% user = apply.user %>
      <tr class="identity-authentication-item identity-authentication-<%= apply.id %>">
        <td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
        <% unless is_processed %>
          <td><%= check_box_tag('ids[]', apply.id, false, id: nil, class: 'batch-check-box') %></td>
        <% end %>
        <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 %>
          <% if user.from_sub_site? %>
            <span class="badge badge-pill badge-info">合作</span>
          <% 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 apply.attachment %>
              <%= image_tag("/api/attachments/#{apply.attachment.id}", 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>
          <td>
            <% if apply.status == 1 %>
              <%= agree_link '撤销', revoke_admins_identity_authentication_path(apply, element: ".identity-authentication-#{apply.id}"), 'data-confirm': '是否确认撤销认证？？' %>
            <% end %>
          </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 } %>