{% extends base_template %}
{% from "macros/audit.html" import m_audit_log with context %}
{% from "macros/comment.html" import m_comments, m_comment_form %}
{% from "macros/attachment.html" import m_attachments, m_attachment_form %}
{% from "macros/box.html" import m_box_content %}
{% from "macros/tag.html" import m_tags_toggle_edit %}

{% block content %}
  {% if title %}<h1>{{ title }}</h1>{% endif %}

  {{ rendered_entity }}

  {% if view.mode == 'view' %}
    {%- if tags.is_support_tagging(view.obj) %}
      <h3>{{ _('Tags') }}</h3>
      {{ m_tags_toggle_edit(view.obj) }}
    {%- endif %}

    <div class="collapsable">
      {%- for view in related_views %}
        {%- if view.size or view.show_empty|default(False) %}
          {%- set default_collapsed = view.default_collapsed|default(True) %}
        <h3 class="{%- if default_collapsed %}collapsed{%- endif %}" data-toggle="collapse"
            href="#panel_{{ loop.index }}">
          {{ view.label }} {%- if view.size %} ({{ view.size }}){%- endif %}
        </h3>

        <div id="panel_{{ loop.index }}" class="collapse {%- if not default_collapsed %} in {%- endif %}" style="margin-bottom: 25px;">
          {{ view.rendered }}
        </div>
        {% endif %}
      {%- endfor %}

      {%- if comments.is_commentable(view.obj) %}
        <h3 href="#panel_comments" data-toggle="collapse">
          {{ _('Comments (%(count)d)', count=comments.count(view.obj)) }}
        </h3>

        <div class="row">
          <div class="col-xs-12
                    col-sm-8 col-sm-push-2
                    col-md-7 col-md-push-3
                    col-lg-6 col-lg-push-3">
            <div id="panel_comments" class="collapse in">
              {{ m_comments(view.obj) }}
              {%- if show_new_comment_form %}
                {{ m_comment_form(view.obj) }}
              {%- endif %}
            </div>

          </div>
        </div>
      {%- endif %}

      {%- set att_manager = attachments.manager(view.obj) %}
      {%- if att_manager.supports_attachments(view.obj) and att_manager.can_view(view.obj) %}
        <div class="row">
          <div class="col-xs-12">
          <h3 href="#panel_attachments" data-toggle="collapse">
            {{ _('Attachments (%(count)d)', count=attachments.count(view.obj)) }}
          </h3>
          <div id="panel_attachments" class="collapse in">
            {{ m_attachments(view.obj) }}
            {%- if show_new_attachment_form and att_manager.can_create(view.obj) %}
              {{ m_attachment_form(view.obj) }}
            {%- endif %}
          </div>
          </div>
        </div>
      {%- endif %}

      {{ m_audit_log(audit_entries) }}
    </div>
  {% endif %}

{% endblock %}
