<% 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="4%">序号</th>
    <th width="8%">头像</th>
    <th width="8%">创建者</th>
    <th width="28%" class="text-left">实训名称</th>
    <th width="8%">审核情况</th>
    <th width="8%">任务数</th>
    <th width="16%">时间</th>
    <% if is_processed %>
      <th width="12%">拒绝原因</th>
      <th width="8%">状态</th>
    <% else %>
      <th width="20%">操作</th>
    <% end %>
  </tr>
  </thead>
  <tbody>
  <% if applies.present? %>
    <% applies.each_with_index do |apply, index| %>
      <% user = apply.user %>
      <% shixun = shixun_map[apply.container_id] %>
      <% content_review = shixun.shixun_reviews.select{|sr| sr.review_type == 'Content'}.first %>
      <% perference_review = shixun.shixun_reviews.select{|sr| sr.review_type == 'Performance'}.first %>
      <tr class="shixun-authorization-item shixun-authorization-<%= apply.id %>">
        <td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
        <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><%= link_to user&.real_name,"/users/#{user&.login}", target: "_blank" %></td>
        <td class="text-left">
          <%= link_to "/shixuns/#{shixun.identifier}", target: '_blank' do %>
            <%= overflow_hidden_span shixun.name, width: 300 %>
          <% end %>
        </td>
        <td>
          <%= check_box_tag :content, content_review&.status, content_review&.status.to_i == 1, class:"shixun-setting-form" ,title:"内容审核", disabled: "disabled"%>
          <%= check_box_tag :perference, perference_review&.status, perference_review&.status.to_i == 1, class:"shixun-setting-form" ,title:"性能审核", disabled: "disabled"%>
        </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 } %>