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

<table class="table table-hover text-center subject-authorization-list-table">
  <thead class="thead-light">
  <tr>
    <th width="4%">序号</th>
    <th width="8%">头像</th>
    <th width="10%">创建者</th>
    <th width="24%" class="text-left">实践课程名称</th>
    <th width="6%">阶段数</th>
    <th width="6%">实训数</th>
    <th width="6%">关卡数</th>
    <th width="14%">时间</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_with_index do |apply, index| %>
      <% user = apply.user %>
      <% subject = subject_map[apply.container_id] %>
      <tr class="subject-authorization-item subject-authorization-<%= apply.id %>">
        <td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
        <td>
          <%= link_to "/users/#{user.login}", class: 'subject-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><%= link_to user&.real_name,"/users/#{user&.login}", target: "_blank" %></td>
        <td class="text-left">
          <%= link_to "/paths/#{subject.id}", target: '_blank' do %>
            <%= overflow_hidden_span subject.name, width: 300 %>
          <% end %>
        </td>
        <td><%= subject.stages_count %></td>
        <td><%= subject.shixuns_count %></td>
        <td><%= challenge_count_map.fetch(subject.id, 0) %></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_subject_authorization_path(apply, element: ".subject-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_subject_authorization_path(apply, element: ".subject-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 } %>