<% cache ["#{@tournament.id}_up_matches", @tournament] do %>
  <script>
    // $(document).ready(function() {
    //   $('#matchList').dataTable();
    // } );
  </script>
  <script>
    setTimeout("location.reload(true);",30000);
  </script>
  <br>
  <br>
  <h5 style="color:red">This page reloads every 30s</h5>
  <br>
  <h3>Upcoming Matches</h3>
  <br>
  <table class="table table-striped table-bordered table-condensed">
    <thead>
      <tr>
        <th>Mat&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
        <th>On Mat</th>
        <th>On Deck</th>
        <th>In The Hole</th>
        <th>Warm Up</th>
      </tr>
    </thead>

    <tbody>
      <% @mats.each.map do |m| %>
        <tr>
          <td><%= m.name %></td>
          <td><% if m.unfinished_matches.first %><strong><%=m.unfinished_matches.first.bout_number%></strong> - <%= m.unfinished_matches.first.weight_max %><br><%= m.unfinished_matches.first.w1_bracket_name %> vs. <%= m.unfinished_matches.first.w2_bracket_name %><% end %></td>
          <td><% if m.unfinished_matches.second %><strong><%=m.unfinished_matches.second.bout_number%></strong> - <%= m.unfinished_matches.second.weight_max %><br><%= m.unfinished_matches.second.w1_bracket_name %> vs. <%= m.unfinished_matches.second.w2_bracket_name %><% end %></td>
          <td><% if m.unfinished_matches.third %><strong><%=m.unfinished_matches.third.bout_number%></strong> - <%= m.unfinished_matches.third.weight_max %><br><%= m.unfinished_matches.third.w1_bracket_name %> vs. <%= m.unfinished_matches.third.w2_bracket_name %><% end %></td>
          <td><% if m.unfinished_matches.fourth %><strong><%=m.unfinished_matches.fourth.bout_number%></strong> - <%= m.unfinished_matches.fourth.weight_max %><br><%= m.unfinished_matches.fourth.w1_bracket_name %> vs. <%= m.unfinished_matches.fourth.w2_bracket_name %><% end %></td>
        </tr>
      <% end %>
    </tbody>
  </table>
  <br>
  <h3>Matches not assigned</h3>
  <br>
  <table class="table table-striped table-bordered table-condensed" id="matchList">
    <thead>
      <tr>
        <th>Round</th>
        <th>Bout Number</th>
        <th>Weight Class</th>
        <th>Matchup</th>
      </tr>
    </thead>

    <tbody>
      <% if @matches.size > 0 %>
      <% @matches.each.map do |m| %>
        <tr>
          <td>Round <%= m.round %></td>
          <td><%= m.bout_number %></td>
          <td><%= m.weight_max %></td>
          <td><%= m.w1_bracket_name %> vs. <%= m.w2_bracket_name %></td>
        </tr>
      <% end %>
      <% end %>
    </tbody>
  </table>

  <br>
<% end %>
