{% from "macros/user.html" import m_user_link, m_user_photo %}

{%- macro m_postinfos(post) %}
  {%- set author_href = url_for("social.user", user_id=post.creator.id) %}
  {%- set thread_href = url_for(".thread", thread_id=post.thread_id, community_id=g.community.slug) %}
  <td>
    <a href="{{ url_for(post) }}">
      <small>{{ post.thread.title }}</small>
    </a>
  </td>
  <td>
    {% call m_user_link(post.creator) %}
      {{ m_user_photo(post.creator, size=35) }}
    {% endcall %}
  </td>

{%- endmacro %}

{%- macro m_postattachments(post) %}
  {%- if post.attachments %}
    <tr>
      {{ m_postinfos(post) }}
      <td colspan="2">
        <table border="0" style="width:100%">
          {%- for attachment in post.attachments %}
            <tr>
              <td style="line-height: 1.5;"><img src="{{ attachment.icon }}" style="vertical-align: middle;" alt=""/>
                <a href="{{ url_for(attachment) }}">{{ attachment.name |truncate(70, False, '...', 0) }}</a>
              </td>

              <td style="float:right;">
                <span style="color:silver;">{{ attachment.content_length|filesize }}</span>
              </td>
            </tr>
          {%- endfor %}
        </table>
      </td>
    </tr>
  {%- endif %}
{%- endmacro %}

{% macro forum_menu(global_actions) %}
  {%- for action in global_actions %}
    {% if loop.index == 2 %}
      <div class="dropdown" style="display: inline;">
        <div
            style="color:#95989A;"
            class="{% if action.is_filtered() %}forum-btn-active {% endif %}btn btn-default dropdown-toggle forum-action-dropdown"
            type="button" id="dropdownMenu2" data-toggle="dropdown" aria-haspopup="true"
            aria-expanded="true">
          {{ action.render() }}
          <span class="glyphicon glyphicon-chevron-down"
                style="position: relative;top: 3px;"></span>
        </div>
        <ul class="dropdown-menu forum-action-dropdownmenu" aria-labelledby="dropdownMenu2">
          <li><a href='{{ url_for(".index", filter="year", community_id=g.community.slug) }}'>Year</a></li>
          <li><a href='{{ url_for(".index", filter="month", community_id=g.community.slug) }}'>Month</a></li>
          <li><a href='{{ url_for(".index", filter="week", community_id=g.community.slug) }}'>Week</a></li>
          <li><a href='{{ url_for(".index", filter="today", community_id=g.community.slug) }}'>Today</a></li>
        </ul>
      </div>
    {% else %}
      <div
          type="button" style="border: none;padding: 10px;display:inline;"
          {% if action.is_current() %}class="forum-btn-active" {% endif %}{% if loop.last %}class="forum-action-conversation"{% endif %}>{{ action.render() }}</div>
    {% endif %}
  {%- endfor %}
{% endmacro %}
