<table class="contest striped">
  <thead>
    <tr>
      <th class="movement"></th>
      <th class="flag"></th>
      <th class="team">Team</th>
      <th class="awards"></th>
      <th class="score">Score</th>
      <th class="win">Win</th>
      <th class="loss">Loss</th>
      <th class="draw">Draw</th>
      <% if actions %>
        <th class="actions"></th>
      <% end %>
    </tr>
  </thead>

  <tbody>
  <% contesters.each do |contester| %>
    <tr>
      <% if contester.trend == Contester::TREND_UP %>
        <td><%= icon 'chevron-up' %></td>
      <% elsif contester.trend == Contester::TREND_DOWN %>
        <td><%= icon 'chevron-down' %></td>
      <% elsif contester.trend == Contester::TREND_FLAT %>
        <td><%= icon 'minus' %></td>
      <% else %>
        <td></td>
      <% end %>
      <td><%= flag contester.team.country %></td>
      <td><%= link_to (h contester.team.name), contester %></td>
      <td><%= icon 'trophy' if contester == contester.contest.winner %></td>
      <td><%= h contester.total_score %></td>
      <td><%= h contester.win %></td>
      <td><%= h contester.loss %></td>
      <td><%= h contester.draw %></td>
      <% if actions %>
        <td class="actions">
          <% if @friendly %>
            <% challenge = Challenge.new
            challenge.contester1 = @friendly
            challenge.contester2 = contester %>
            <% if challenge.can_create? cuser %>
              <%= link_to 'C', controller: 'challenges', id: contester, action: 'new' %>
            <% end %>
          <% end %>
          <% if cuser and cuser.admin? %>
            <%= link_to icon('pencil'), edit_contester_path(contester) %>
            <%= link_to icon('times'), contester, confirm: 'Are you sure?', method: :delete %>
          <% end %>
        </td>
      <% end %>
    </tr>
  <% end %>
  </tbody>
</table>