<style>
  .pagination a {
    color: #FFCC66;
    text-decoration: none;
  }
  .pagination{
    padding-top:10px;
    padding-buttom:10px;
    width:600px;
    text-align: center;
  }

  #duels{width: 600px;text-align: center}
  #duels thead {line-height:25px; background-color:#1c1b1b; height:25px; color:#d6edff; font-weight:bold; }
  #duels tbody {line-height:25px; padding-top:3px; font-weight:bold;}
  #duels .index {color:white}
  #duels .win {color:#58db3e}
  #duels .lose {color:red}
  #duels .current {color:red}
</style>
<table id="duels">
  <thead>
    <tr>
      <% if @user %>
        <th>场次</th>
        <th>对手</th>
        <th>胜负</th>
        <th>得分</th>
      <% else %>
        <th>场次</th>
        <th>玩家1</th>
        <th>玩家2</th>
        <th>玩家1得分</th>
        <th>玩家2得分</th>
      <% end %>
    </tr>
  </thead>
  <tfoot>
    <tr><td colspan="7"><%= will_paginate @duels %></td></tr>
  </tfoot>
  <tbody>
    <% first_index = @user.duels.where("id<=?",@duels.to_enum.first.id).count if @user and !@user.duels.empty? %><!--这里的效率很低，待优化-->
    <% @duels.each_with_index do |duel, index| %>
      <tr>
        <% if @user %>
          <td class="index"><%= link_to (first_index - index), duel %></td>
          <td class="user opponent"><% opponent = duel.user1 == @user ? duel.user2 : duel.user1 %><%= link_to opponent.name, opponent %></td>
          <td class="result <%= duel.winner == @user ? "win" : "lose" %>"><%= duel.winner == @user ? "WIN" : "LOSE" %></td>
          <td class="credits <%= duel.winner == @user ? "win" : "lose" %>"><%= duel.user1 == @user ? duel.user1_credits : duel.user2_credits %></td>
        <% else %>
          <td class="index"><%= link_to duel.id, duel %></td>
          <td class="user user1"><%= link_to duel.user1.name, duel.user1 %></td>
          <td class="user user2"><%= link_to duel.user2.name, duel.user2 %></td>
          <td class="credits user1 <%= duel.winner == duel.user1 ? "win" : "lose" %>"><%= duel.user1_credits %></td>
          <td class="credits user2 <%= duel.winner == duel.user2 ? "win" : "lose" %>"><%= duel.user2_credits %></td>
        <% end %>
      </tr>
    <% end %>
  </tbody>
</table>


