<div id="team-profile">
  <h1 class="fancy">
    <span><%=h @team.name %></span>
  </h1>

  <% if @team.logo %>
    <div class="logo">
      <%= image_tag @team.logo.url, class: 'logo', alt: h(@team.name) %>
    </div>
  <% end %>

  <div id="team" class="tabbed">
    <ul id="team-nav" class="tabs">
      <li><a href="#general">General</a></li>
      <li><a href="#members">Members</a></li>
      <li><a href="#matches">Matches</a></li>
      <li><a href="#statistics">Statistics</a></li>
    </ul>

    <div class="tabbed-contents">
      <div class="tab" id="general">
        <dl>        
          <dt>IRC:</dt>
          <dd><%=h @team.irc %></dd>
          <dt>Web:</dt>
          <dd><%=h @team.web %></dd>
          <dt>Tag:</dt>
          <dd><%=h @team.tag %></dd>
          <dt>Country:</dt>
          <dd><%=h @team.country %></dd>
          <dt>Founder:</dt>
          <dd><%= namelink @team.founder %></dd>
          <dt>Comment:</dt>
          <dd><%=h @team.comment %></dd>
          <% if @team.recruiting %>
            <dt>Recruiting:</dt>
            <dd><%=h @team.recruiting %></dd>
          <% end %>
        </dl>

        <%= link_to "Send a message", { controller: "messages", action: "new", id: "Team", id2: @team }, { class: 'button tiny' } %>
      </div>

      <div class="tab" id="members">
        <% if @team.teamers.active.ordered.distinct.length > 0 %>
          <h3>Current Members</h3>
          <%= render partial: "teamers/list", locals: { teamers: @team.teamers.active.ordered.distinct, blacklist: false, comment: true } %>
        <% end %>

        <% if @team.teamers.past.distinct.length > 0 %>
          <h3>Past Members</h3>
          <%= render partial: "teamers/list", locals: { teamers: @team.teamers.past.distinct, blacklist: @team.teamers.active.ordered.distinct, comment: false } %>
        <% end %>
      </div>

      <div class="tab" id="matches">
        <% @team.contesters.chronological.each do |contester| %>
          <% next if Match.finished.ordered.of_contester(contester).count == 0 %>
          <h3>
            <%= link_to contester.contest, contester.contest, :name => "contest_#{contester.contest.id}" %>
          </h3>
          <%= render partial: "matches/list", locals: { matches: Match.finished.ordered.of_contester(contester), friendly: contester.team, contest: false } %>
        <% end %>
      </div>

      <div class="tab" id="matches">
        <dl>
          <dt>Matches:</dt>
          <dd><%= @team.matches_finished.count %> played / <%= @team.matches.count %> total</dd>
          <dt>Won:</dt>
          <dd><%= @team.matches_won.count %> (<%= 100.0*@team.matches_won.count/@team.matches_finished.count %> %)</dd>
          <dt>Lost:</dt>
          <dd><%= @team.matches_lost.count %> (<%= 100.0*@team.matches_lost.count/@team.matches_finished.count %> %)</dd>
          <dt>Draw:</dt>
          <dd><%= @team.matches_draw.count %> (<%= 100.0*@team.matches_draw.count/@team.matches_finished.count %> %)</dd>
        </dl>
      </div>
    </div>
  </div>

  <script type="text/javascript">
    new Yetii({
      id: 'team',
      active: 2
    });
  </script>

  <% if cuser and @team.can_update? cuser %>
    <div class="controls">
      <%= link_to 'Edit Team', edit_team_path(@team), class: 'button' %>
    </div>
  <% end %>
</div>
