{% load i18n cms_tags %}

{% regroup object_list|dictsort:"category_id" by category as qgroups %}

<div class="panel panel-primary">
    {% for qgroup in qgroups %}
        {% if list %}
            <div class="panel-heading">
                <h3 class="panel-title">{{ qgroup.grouper }}</h3>
            </div>
        {% endif %}
        <div class="list-group">
            {% for question in qgroup.list %}
                {% if view.config.app_data.config.show_description %}
                    <a href="{{ question.get_absolute_url }}" class="list-group-item">
                        <h3 class="list-group-item-heading">
                            {% render_model question "title" %}
                            {% if not list %}<span class="badge">{{ qgroup.grouper }}</span>{% endif %}
                            {% for tag in question.tags.all %}
                                <span class="badge">{{ tag }}</span>
                            {% endfor %}
                        </h3>
                        <div class="list-group-item-text">
                            {% render_model question "answer_text" %}
                        </div>
                    </a>
                {% else %}
                    <a href="{{ question.get_absolute_url }}" class="list-group-item">
                        {% render_model question "title" %}
                        {% if not list %}<span class="badge">{{ qgroup.grouper }}</span>{% endif %}
                        {% for tag in question.tags.all %}
                            <span class="badge badge-default pull-right">{{ tag }}</span>
                        {% endfor %}
                    </a>
                {% endif %}
            {% endfor %}
        </div>
    {% empty %}
        {% if list %}
            <div class="panel-heading">
                <h3 class="panel-title">{{ qgroup.grouper|default:_("Category") }}</h3>
            </div>
        {% endif %}
        <div class="list-group">
            <p class="list-group-item">{% trans "No entry found." %}</p>
        </div>
    {% endfor %}
</div>

{% if list and title %}
    {% include "aldryn_faq/includes/pager.html" with title=_("Back to Category") slug=object.category.get_absolute_ur %}
{% endif %}
