<style>
  #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}

  #user p {text-align: left}
  #user #avatar{float:right}
  #user_nickname{width: 150px}
  #user_email{width: 150px}
  .card  {float:left; padding-left:10px; padding-bottom:9px;}
  .card img{width:40px; height:50px; border:0px;}
  .user{  width:330px; font-size:20px; color:#ffcc66; float:left; cursor:pointer;  line-height:40px;padding-left: 12px;font-weight: bold;}
  .user_act{  width:330px; font-size:20px; color:#ffcc66; float:left; cursor:pointer; background-color:#111111; line-height:40px;padding-left: 12px;font-weight: bold;}
  #cards{background-color:#111111; overflow:hidden; padding:12px;text-align: left}
</style>

<div id="user">
  <% if @user == @current_user %>
    <%= render 'form' %>
  <% else %>
    <div id="avatar">
      <div><%= image_tag @user.avatar.url(:middle) %></div>
    </div>
    <p><%= User.human_attribute_name :name %>: <%= @user.name %> </p>
    <% unless @user.nickname.blank? %><p><%= User.human_attribute_name :nickname %>: <%= @user.nickname %></p><% end %>
    <p><%= User.human_attribute_name :id %>: <%= @user.id %></p>
    <p><%= User.human_attribute_name :email %>: <%= @user.email %></p>
    <p><%= User.human_attribute_name :created_at %>: <%=l @user.created_at, :format => :long %></p>
    <p><%= Duel.human_attribute_name :record %>：<%= @user.wins.count %> <%= Duel.human_attribute_name :wins %>, <%= @user.losts.count %> <%= Duel.human_attribute_name :losses %>, <%= Duel.human_attribute_name :total %>: <%= @user.duels.count %></p>
  <% end %>
</div>

<div style="clear:both"></div>
<div id="cards">
  <p><b><%= User.human_attribute_name :top_monsters %>:</b> </p>
  <% @user.cards.main_monsters.top(10).each do |card| %>
    <div class="card">
      <%= link_to image_tag(card.image, :title => card.name), card %>
    </div>
  <% end %>

  <div style="clear:both"></div>
  <p><b><%= User.human_attribute_name :top_extras %>:</b> </p>
  <% @user.cards.extra.top(5).each do |card| %>
    <div class="card">
      <%= link_to image_tag(card.image, :title => card.name), card %>
    </div>
  <% end %>

  <div style="clear:both"></div>
  <p><b><%= User.human_attribute_name :top_spells %>:</b> </p>
  <% @user.cards.magics.top(5).each do |card| %>
    <div class="card">
      <%= link_to image_tag(card.image, :title => card.name), card %>
    </div>
  <% end %>

  <div style="clear:both"></div>
  <p><b><%= User.human_attribute_name :top_traps %>:</b> </p>
  <% @user.cards.traps.top(5).each do |card| %>
    <div class="card">
      <%= link_to image_tag(card.image, :title => card.name), card %>
    </div>
  <% end %>
</div>


<table id="duels">
  <thead>
    <tr>
      <th><%= Duel.human_attribute_name :id %></th>
      <th><%= Duel.human_attribute_name :opponent %></th>
      <th><%= Duel.human_attribute_name :result %></th>
      <th><%= Duel.human_attribute_name :points %></th>
      <th><%= Duel.human_attribute_name :total_points %></th>
    </tr>
  </thead>
  <tfoot>
    <tr>
      <td colspan="5"><%= link_to t('more'), {:controller => :duels, :action => :index, :user_id => @user.id} %></td>
    </tr>
  </tfoot>
  <tbody>
    <% final_credits = @user.credits %>
    <% @user.top_duels(20).each_with_index do |duel, index| %>
      <tr>
        <td class="index"><%= link_to (@user.duels.count - index), duel %></td>
        <td class="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>
        <td class="final_credits <%= "current" if index.zero? %>"><%= final_credits %><% final_credits -= duel.user1 == @user ? duel.user1_credits : duel.user2_credits %></td>
      </tr>
    <% end %>
  </tbody>
</table>
