<!--
SPDX-FileCopyrightText: 2025-present Tobias Kunze
SPDX-License-Identifier: AGPL-3.0-only WITH LicenseRef-Pretalx-AGPL-3.0-Terms
-->

{% extends "orga/submission/base.html" %}

{% load i18n %}
{% load rich_text %}
{% load rules %}
{% load static %}

{% block scripts %}
    {{ block.super }}
    <script defer src="{% static "orga/js/ui/comments.js" %}"></script>
{% endblock scripts %}

{% block submission_content %}
    {% has_perm 'submission.create_submissioncomment' request.user submission as can_add_comment %}

    <div class="comments-list">
        {% if not comments %}
            <div class="alert alert-info">
                {% translate "No comments yet." %}
            </div>
        {% endif %}

        {% for comment in comments %}
            <div class="comment card mb-4" id="comment-{{ comment.pk }}">
                <div class="comment-header card-header">
                    <strong>
                        {% include "orga/includes/user_name.html" with user=comment.user lightbox=True %}
                    </strong>
                    <div class="text-muted ml-auto">
                        {{ comment.created|date:"SHORT_DATETIME_FORMAT" }}
                    </div>
                    {% has_perm 'submission.delete_submissioncomment' request.user comment as can_delete_comment %}
                    {% if can_delete_comment %}
                        <a href="{{ comment.urls.delete }}" class="btn btn-sm btn-danger ml-2">
                            <i class="fa fa-trash" title="{{ phrases.base.delete_button }}"></i>
                        </a>
                    {% endif %}
                </div>
                <div class="comment-content card-body">
                    {{ comment.text|rich_text }}
                </div>
            </div>
        {% endfor %}
    </div>

    {% if can_add_comment %}
        <form method="post">
            {% csrf_token %}
            <div class="comment card">
                <div class="comment-header card-header">
                    <strong>
                        {% include "orga/includes/user_name.html" with user=request.user lightbox=True %}
                    </strong>
                </div>
                <div class="comment-content card-content">
                    <div class="m-4">
                        {{ form }}
                    </div>
                </div>
            </div>
            {% translate "Add comment" as submit_label %}
            {% include "orga/includes/submit_row.html" %}
        </form>
    {% endif %}

{% endblock %}
