<h1>Editing team: <%= h @team.name %></h1>

<div id="teamsTab">
  <ul id="teamsTab-nav" class="tabs">
    <li><a href="#detailsTab">Details</a></li>
    <li><a href="#membersTab">Members</a></li>
    <li><a href="#contestsTab">Contests</a></li>
  </ul>

  <div class="box wide tabs">
    <div id="detailsTab" class="tab">
      <%= form_for @team, :html => {:multipart => true} do |f| %>
        <%= f.error_messages %>
        <p>
          <%= f.label :name %><br />
          <%= f.text_field :name %>
        </p>
        <p>
          <%= f.label :irc %><br />
          <%= f.text_field :irc %>
        </p>
        <p>
          <%= f.label :web %><br />
          <%= f.text_field :web %>
        </p>
        <p>
          <%= f.label :tag %><br />
          <%= f.text_field :tag %>
        </p>
        <p>
          <%= f.label :country %><br />
          <%= country_code_select :team, :country %>
        </p>
        <p>
          <%= f.label :comment %><br />
          <%= f.text_field :comment %>
        </p>
        <p>
          <%= f.label :recruiting %><br />
          <%= f.text_field :recruiting %><br />
          Leave empty if you are not recruiting, otherwise write the recruiting criteria above.
        </p>
        <p>
          <%= f.label :logo %><br />
          <%= f.file_field :logo %><br />
        </p>
        <p>
          <%= f.submit "Update" %>
        </p>
      <% end %>
    </div>

    <div id="membersTab" class="tab">
      <%= form_for @team do |f| %>
        <table class="data">
          <tr>
            <th>Name</th>
            <th>Comment</th>
            <th>Rank</th>
            <th>Actions</th>
          </tr>
          <% @team.teamers.present.each do |member|  %>
            <tr class="<%= cycle('even', 'odd') %>">
              <td <% if member.team_id == member.user.team_id %>id="teamsPrimary"<% end %>>
                <%= link_to (h member.user.username), member.user %>
              </td>
              <td>
                <%= text_field_tag "comment[#{member.id}]", (h member.comment) %>
              </td>
              <td>
                <%= select_tag "rank[#{member.id}]", options_for_select(member.ranks.invert, member.rank) %>
              </td>
              <td>
                <%= link_to 'Remove', member, :confirm => 'Are you sure?', :method => :delete%>
              </td>
            </tr>
          <% end %>
        </table>
        <p>
          <%= f.submit "Update" %>
        </p>
      <% end %>
    </div>

    <div id="contestsTab" class="tab">
      <p>
        <%= form_for @team.contesters.build do |f| %>
          <%= f.hidden_field :team_id %>
          <%= f.collection_select :contest_id, Contest.active, :id, :name  %>
          <%= f.submit "Join" %>
        <% end %>
      </p>
    </div>
  </div>
</div>

<script type="text/javascript">
  var tabber1 = new Yetii({id: 'teamsTab'});
</script>

<%= link_to 'Show', @team %> |
<%= link_to 'Back', teams_path %>
