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

<table class="table table-hover text-center shixun-authorization-list-table">
  <thead class="thead-light">
  <tr>
    <th width="8%">头像</th>
    <th width="14%">创建者</th>
    <th width="28%" class="text-left">实训名称</th>
    <th width="12%">任务数</th>
    <th width="16%">时间</th>
    <% if is_processed %>
      <th width="14%">拒绝原因</th>
      <th width="8%">状态</th>
    <% else %>
      <th width="22%">操作</th>
    <% end %>
  </tr>
  </thead>
  <tbody>
  <% if applies.present? %>
    <% applies.each do |apply| %>
      <% user = apply.user %>
      <% shixun = shixun_map[apply.container_id] %>
      <tr class="shixun-authorization-item shixun-authorization-<%= apply.id %>">
        <td>
          <%= link_to "/users/#{user.login}", class: 'shixun-authorization-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 class="text-left">
          <%= link_to "/shixuns/#{shixun.identifier}", target: '_blank' do %>
            <%= overflow_hidden_span shixun.name, width: 300 %>
          <% end %>
        </td>
        <td><%= shixun.challenges_count %></td>
        <td><%= apply.updated_at.strftime('%Y-%m-%d %H:%M') %></td>

        <% if is_processed %>
          <td class="text-secondary"><%= overflow_hidden_span apply.reason, width: 140 %></td>
          <td><span class="apply-status-<%= apply.status %>"><%= apply.status_text %></span></td>
        <% else %>
          <td class="action-container">
            <%= agree_link '同意', agree_admins_shixun_authorization_path(apply, element: ".shixun-authorization-#{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_shixun_authorization_path(apply, element: ".shixun-authorization-#{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 } %>