<%= provide :content_class, 'no-body' %>

<div class="breadcrumbs">
  <%= link_to "Forums", action: "index" %> <%= icon 'chevron-right' %> <%= namelink @forum %>
</div>

<div class="topic-controls">
  <%= render partial: 'controls', locals: { forum: @forum } %>  
</div>

<h2><%=h @forum.title %></h2>

<%= will_paginate @topics %>

<table id="topics" class="striped">
  <thead>
    <tr>
      <th class="topic">Topic</th>
      <th class="author">Author</th>
      <th class="replies">Replies</th>
      <th class="views">Views</th>
      <th class="last">Last Post</th>
    </tr>  
  </thead>
  
  <% @topics.each do |topic| %>
    <tr>
      <td>
        <h5>
          <% if topic.state == Topic::STATE_STICKY %>
            <b>Sticky: </b>
          <% elsif topic.lock %>
            <b>Locked: </b>
          <% end %>

          <%= link_to (h topic), topic,
              class: ((cuser and !topic.read_by? cuser) ? "unread" : "read") +
                     ((topic.state == Topic::STATE_STICKY) ? " sticky" : "") %>
        </h5>

        <% if topic.posts.count > Topic::POSTS_PAGE %>
          Page:
          <% (1..((topic.posts.count/Topic::POSTS_PAGE).ceil + 1)).to_a.each do |page| %>
            <%= ", " unless page == 1 %>
            <%= link_to page, topic_url(topic, page: page) %>
          <% end %>
        <% end %>
      </td>
      <td><%= namelink(topic.user) %></td>
      <td><%=h topic.cached_posts_count %></td>
      <td><%=h topic.cached_view_count %></td>
      <td>
        <%= link_to lastpost(topic) do %>
          <%=h topic.latest.user %><br>
          <%= shortdate(topic.latest.created_at) %>
        <% end %>
      </td>
    </tr>
  <% end %>
</table>

<%= will_paginate @topics %>

<%= render partial: 'controls', locals: { forum: @forum } %>
