<% back_to_school_path = school_path(@school) %>
<% back_to_school_path += "?school_permission_key=#{params[:school_permission_key]}" if params[:school_permission_key].present? %>

<%= link_to "Back to #{@school.name}", back_to_school_path, class: "btn btn-default" %>
<% cache ["#{@school.id}_Stats", @school] do %>
  <br>
  <br>
  <h2><%= @school.name %> Stats Summary</h2>
  <br>
  <h4>Matches</h4>
  <br>
  <table class="table">
    <thead>
      <tr>
        <th>Wrester</th>
        <th>Weight Class</th>
        <th>Bout</th>
        <th>Match Bracket Position</th>
        <th>Stats</th>
        <th>Result</th>
      </tr>
    </thead>
    <tbody>
      <% @school.wrestlers.each do |wrestler| %>
        <% wrestler.all_matches.each do |m| %>
          <tr>
            <td><%= wrestler.name %></td>
            <td><%= wrestler.weight.max %></td>
            <td><%= m.bout_number %></td>
            <td><%= m.bracket_position %></td>
            <td>
              <table class="table table-sm table-bordered">
                
                <tbody>
                  <tr>
                    <td><%= m.w1_bracket_name.html_safe %></td>
                    <td><%= m.w1_stat %></td>
                  </tr>
                  <tr>
                    <td><%= m.w2_bracket_name.html_safe %></td>
                    <td><%= m.w2_stat %></td>
                  </tr>
                </tbody>
              </table>
            </td>
            <td><%= wrestler.result_by_id(m.id) %>
          </tr>
        <% end %>
      <% end %>
    </tbody>
  </table>
<% end %>

