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

{% macro m_comments(entity) %}
  {%- if comments.has_comments(entity) %}
    <ol class="comments">
    {%- for comment in comments.for_entity(entity) %}
      <li id="comment-{{ comment.id }}">{{ m_comment(comment) }}</li>
    {%- endfor %}
    </ol>
  {%- endif %}
{% endmacro %}

{# single comment #}
{% macro m_comment(comment) %}
  <div class="header">
  {%- call m_user_link(comment.creator) %}
    {{ m_user_photo(comment.creator, size=45) }}
  {%- endcall %}
  
  {%- call m_user_link(comment.creator, css='author') %}
    {{ comment.creator.name }}
  {%- endcall %}
  <span class="date"><small>{{ comment.created_at | age }}</small></span>
  </div>
  
  <p> {{ comment.body |nl2br }} </p>
{% endmacro %}

{% macro m_comment_form(entity) %}
  {%- set ctx = comments.get_form_context(entity) %}
  <form action="{{ ctx.url }}" method="POST" enctype="multipart/form-data" role="form">
    {%- for field in ctx.form %}
      {{ m_field(field) }}
    {%- endfor %}

    <div class="form-group form-actions">
      {%- for button in ctx.buttons %}
        {{ button.render() }}
      {%- endfor %}
    </div>
  </form>
{% endmacro %}
