<div id="categories">
  <% @categories.each do |cat| %>
    <% forums = cuser ? cat.forums.available_to(cuser, Forumer::ACCESS_READ).ordered : cat.forums.public.ordered %>
    <% next if forums.length == 0 %>

    <h3><%=h cat.name %></h3>
    <div class="category">
      <table class="category">
        <tr>
          <th colspan="2" class="forums">Forums</th>
          <th class="actions"></th>
          <th class="topics">Topics</th>
          <th class="posts">Posts</th>
          <th class="last">Last Post</th>
        </tr>

        <% forums.each do |forum| %>
          <tr>
            <td class="bullet <%= "highlight" if cuser and !forum.read_by?(cuser) %>"></td>
            <td class="forum">
              <h5><%= namelink(forum) %></h5>
              <%= forum.description %>
            </td>
            <td class="actions">
              <% if forum.can_update? cuser %>
                <%= link_to action: "up", id: forum do %>
                  <% icon 'arrow-up' %>
                <% end %>
                <%= link_to action: "down", id: forum do %>
                  <% icon 'arrow-down' %>
                <% end %>
              <% end %>
            </td>
            <td class="topics"><%= forum.topics.count %></td>
            <td class="posts"><%= forum.posts.count %></td>
            <td class="last">
              <% if forum.posts.last %>
                <%= link_to lastpost(forum.posts.last.topic) do %>
                  <%=h forum.posts.last.user %><br>
                  <%= shortdate(forum.posts.last.created_at) %>
                <% end %>
              <% end %>
            </td>
          </tr>
        <% end %>
      </table>
    </div>
  <% end %>
</div>

<div class="statistics">
  <h4>Statistics</h4>
  <p>
    We have total of <strong><%= Post.count %></strong> posts,
    <strong><%= Topic.count %></strong> topics, and <strong><%= User.count %></strong> users.
  </p>
  <p>
    Our newest member is <%= namelink User.last %> and most active member is <%= namelink User.posts_stats.first %>.
  </p>
</div>

<% if Forum.new.can_create? cuser %>
  <p>
    <%= link_to 'New forum', new_forum_path, class: "button" %>
  </p>
<% end %>
