<div id='sidebar'>
  <div class='panel'>
    <% if (locals.current_user) { %>
    <div class='inner'>
      <%- partial('user/card', { object: current_user, as: 'user' }) %>
    </div>
    <% } else { %>
    <div class='inner'>
      <p><%= config.description %></p>
      <div class='sep10'></div>
      <div class='cen'>
        <a href='/signup'><button class='btn'>现在注册</button></a>
        <div class='sep10'></div>
        <span>已注册用户请<a class='light' href='/signin'> 登录</a></span>
      </div>
    </div>
    <% } %>
  </div>
  <div class='sep10'></div>
  <div class='panel'>
    <div class='header'>
      <span class='col_fade'>热门话题</span>
    </div>
    <div class='inner'>
      <% if (locals.hot_topics && hot_topics.length > 0) { %>
      <ul class='unstyled'>
      <%- partial('topic/small', { collection: hot_topics, as: 'topic' }) %>
      </ul>
      <% } else { %>
      <p>无</p>
      <% } %>
    </div>
  </div>
  <div class='sep10'></div>
  <div class='panel'>
    <div class='header'>
      <span class='col_fade'>无人回复的话题</span>
    </div>
    <div class='inner'>
      <% if (locals.no_reply_topics && no_reply_topics.length > 0) { %>
      <ul class='unstyled'>
      <%- partial('topic/small', { collection: no_reply_topics, as: 'topic' }) %>
      </ul>
      <% } else {  %>
      <p>无</p>
      <% } %>
    </div>
  </div>

</div>

<div id='content'>
  <div class='panel'>
    <div class='header'>
      <ul class='breadcrumb'>
        <li><a href='/'>主页</a><span class='divider'>/</span></li>
        <% if (locals.tag) { %>
        <li class='active'><%= tag.name %></li>
        <% } else { %>
        <li class='active'>错误</li>
        <% } %>
      </ul>
      <% if (locals.tag) { %>
      <div class='sep5'></div>
      <span class='col_fade'><%= tag.description %></span>
      <% } %>
      <% if (locals.current_user) { %>
        <% if (!locals.error) { %>
        <div class='sep10'></div>
        <div class='sep10'></div>
        <a href='/topic/create'><button class='btn' id='create_topic_btn'>发布话题</button></a>
          <% if (!locals.in_collection) { %>
          <button class='btn btn-success fr' id='collect_btn' action='collect'>加入收藏</button>
          <% } else { %>
          <button class='btn fr' id='collect_btn' action='de_collect'>取消收藏</button>
          <% } %>
        <% } %>
      <% } %>
    </div>

    <% if (locals.error) { %>
    <div class='inner'>
      <div class="alert alert-error" >  
        <strong><%= error %></strong>
      </div>
    </div>
    <% } else { %>
      <% if (locals.topics && topics.length > 0) { %>
      <%- 
      partial('topic/list', { 
        topics: topics, pages: pages, 
        current_pages: current_page, 
        base: '/tag/' + tag.name
      }) %>
      <% } else { %>
      <div class='inner'>
        <p>无话题</p>
      </div>
      <% } %>
    <% } %>
  </div>
</div>

<% if (locals.current_user && locals.tag) { %>
<script type='text/javascript'>
$(document).ready(function(){
  $('#collect_btn').click(function() {
    var $me = $(this);
    var action = $me.attr('action');
    var data = {
      tag_id: '<%= tag._id %>',
      _csrf: '<%= csrf %>'
    };
    $.post('/tag/' + action, data, function(data) {
      if (data.status === 'success') {
        if (action === 'collect') {
          $me.html('取消收藏');
          $me.attr('action','de_collect');
        } else {
          $me.html('加入收藏');
          $me.attr('action','collect');
        }
        $me.toggleClass('btn-success'); 
      } 
    }, 'json'); 
  });
});
</script>
<% } %>
