<div class="box wide">
  <h1><%= @title %> (<%= number_with_delimiter(@user_count) %>)</h1>

  <% if @newest %>
    <p>
    Newest users:
    <% @newest.each do |user| %>
      <%= styled_user_link user %>
      <%= user_karma(user) %><%= ',' if user != @newest.last %>
    <% end %>
    </p>
  <% end %>

  <ul class="tree user_tree noparent">

    <% subtree = @users_by_parent[nil] %>
    <% ancestors = [] %>

    <% while subtree %>
      <% if (user = subtree.pop) %>
        <li class="<%= user.invited_by_user_id ? "" : "noparent" %>">
          <%= styled_user_link user, nil, name: user.username  %>
          <%= user_karma(user) %>

          <% if (children = @users_by_parent[user.id]) %>
            <% # drill down deeper in the tree %>
            <% ancestors << subtree %>
            <% subtree = children %>
            <ul class="user_tree">
          <% else %>
            </li>
          <% end %>
      <% else %>
        <% # climb back out %>
        <% subtree = ancestors.pop %>
        <% if subtree %>
          </ul></li>
        <% end %>
      <% end %>
    <% end %>
  </ul>
</div>
