<p>
  <strong>Name:</strong>
  <%= @school.name %>
  <% if can? :manage, @school %>
    <% edit_school_path_with_key = edit_school_path(@school) %>
    <% edit_school_path_with_key += "?school_permission_key=#{params[:school_permission_key]}" if params[:school_permission_key].present? %>
    <%= link_to " Edit", edit_school_path_with_key, class: "fas fa-edit" %>
  <% end %>
</p>

<p>
  <strong>Team Points Deducted:</strong>
  <%= @school.total_points_deducted %>
</p>

<p>
  <strong>Score:</strong>
  <%= @school.score %>
</p>

<p>
  <strong>Tournament:</strong>
  <%= @school.tournament.name %>
</p>

<% stat_summary_path_with_key = "/schools/#{@school.id}/stats" %>
<% stat_summary_path_with_key += "?school_permission_key=#{params[:school_permission_key]}" if params[:school_permission_key].present? %>
<%= link_to "#{@school.name} Stat Summary", stat_summary_path_with_key, class: "btn btn-sm btn-primary" %> 

<br><br>

<h3>Roster</h3>
<p>(Click wrestler to see their score breakdown and match list)</p>

<table class="table table-hover table-condensed">
  <thead>
    <tr>
      <th>Name</th>
      <th>Weight</th>
      <th>Record/Seed Criteria</th>
      <th>Seed</th>
      <th>Team Points Scored</th>
      <th>Extra?</th>
      <th>Next Bout/Mat</th>
      <% new_wrestler_path_with_key = new_wrestler_path(school: @school.id) %>
      <% new_wrestler_path_with_key += "&school_permission_key=#{params[:school_permission_key]}" if params[:school_permission_key].present? %>

      <% if can? :manage, @school %>
        <th><%= link_to " New Wrestler", new_wrestler_path_with_key, class: "fas fa-plus" %></th>
      <% end %>
    </tr>
  </thead>

  <tbody>
    <% @wrestlers.sort_by { |w| w.weight.max }.each do |wrestler| %>
      <% if params[:school_permission_key].present? %>
        <tr>
          <%= render "schools/wrestler_row_cells", wrestler: wrestler, school_permission_key: params[:school_permission_key] %>

          <% if can? :manage, wrestler.school %>
            <td>
              <% edit_wrestler_path_with_key = edit_wrestler_path(wrestler) %>
              <% edit_wrestler_path_with_key += "?school_permission_key=#{params[:school_permission_key]}" if params[:school_permission_key].present? %>

              <% delete_wrestler_path_with_key = wrestler_path(wrestler) %>
              <% delete_wrestler_path_with_key += "?school_permission_key=#{params[:school_permission_key]}" if params[:school_permission_key].present? %>

              <%= link_to edit_wrestler_path_with_key, class: "text-decoration-none" do %>
                <span class="fas fa-edit" aria-hidden="true"></span>
              <% end %>
              <%= link_to delete_wrestler_path_with_key, data: { turbo_method: :delete, turbo_confirm: "Are you sure you want to delete #{wrestler.name}? This will delete all of his matches." }, class: "text-decoration-none" do %>
                <span class="fas fa-trash-alt" aria-hidden="true"></span>
              <% end %>
            </td>
          <% end %>
        </tr>
      <% else %>
        <tr>
          <% cache ["school_show_wrestler_cells", wrestler] do %>
            <%= render "schools/wrestler_row_cells", wrestler: wrestler %>
          <% end %>
          <% if can? :manage, wrestler.school %>
            <td>
              <%= link_to edit_wrestler_path(wrestler), class: "text-decoration-none" do %>
                <span class="fas fa-edit" aria-hidden="true"></span>
              <% end %>
              <%= link_to wrestler_path(wrestler), data: { turbo_method: :delete, turbo_confirm: "Are you sure you want to delete #{wrestler.name}? This will delete all of his matches." }, class: "text-decoration-none" do %>
                <span class="fas fa-trash-alt" aria-hidden="true"></span>
              <% end %>
            </td>
          <% end %>
        </tr>
      <% end %>
    <% end %>
  </tbody>
</table>

<%# if can? :manage, @school %>
  <%#= render 'baums_roster_import' %>
<%# end %>
