{% extends 'django_spire/card/title_card.html' %}

{% load permission_tags %}
{% load model_tags %}

{% block card_title %}
    Comments
{% endblock %}

{% block card_button %}
    {% with app_label=obj|model_app_label model_name=obj|model_name %}
        {% check_permission user app_label model_name 'change' as has_access %}
        {% if has_access %}
            <span
                    @click="dispatch_modal_view('{% url "django_spire:comment:form_content" obj_pk=obj.pk comment_pk=0 app_label=app_label model_name=model_name %}')"
            >
                    {% include 'django_spire/button/primary_button.html' with button_text='Add' button_icon='bi bi-plus' %}
                </span>
        {% endif %}
    {% endwith %}
{% endblock %}

{% block card_title_content %}
    {% with obj.comments.active.prefetch_user as comments %}
        {% if comments %}
            {% for comment in comments %}
                {% include 'django_spire/comment/item/comment_item.html' %}
            {% endfor %}
        {% else %}
            {% include 'django_spire/item/no_data_item.html' %}
        {% endif %}
    {% endwith %}
{% endblock %}
