{% load i18n %}
{% load comments %}
{% load comments_ink %}

<div
  id="comments"
  class="comment-list"
  {% if comment_reactions_enabled %}
    data-dci="config"
    {% if user.is_authenticated %}
      data-react-url="{% url 'comments-ink-react' 0 %}"
    {% else %}
      data-login-url="{% url 'login' %}"
    {% endif %}
    data-guest-user="{% if user.is_authenticated %}0{% else %}1{% endif %}"
    data-page-qs-param="{{ comments_page_qs_param }}"
    data-fold-qs-param="{{ comments_fold_qs_param }}"
  {% endif %}
>
  {% if is_paginated %}
    {% include "comments/pagination.html" %}
  {% endif %}

  {% for comment in comment_list %}
    {% comment %}
      # Before rendering the comment, check the reply_stack to find out
      # whether a reply-box has to be rendered.
    {% endcomment %}
    {% if reply_stack %}
      {% with top_comment=reply_stack|get_top_comment %}
        {% if comment.level <= top_comment.level %}
          {% for object in reply_stack|pop_comments_gte:comment.level %}
            {% if object.allow_thread %}
              {% include "comments/reply_button.html" with comment=object %}
            {% endif %}
          {% endfor %}
          {% push_comment comment %}
        {% elif comment.level > top_comment.level and comment.level < max_thread_level %}
          {% push_comment comment %}
        {% endif %}
      {% endwith %}
    {% else %}
      {% push_comment comment %}
    {% endif %}

    {% block comment %}
      {% with page_number=page_obj.number %}
        {% include "comments/comment.html" %}
      {% endwith %}
    {% endblock %}

    {% if forloop.last %}
      {% comment %}
        # After rendering the last comment, render the reply form for the
        # rest of comments still queued in the reply_stack.
      {% endcomment %}
      {% for object in reply_stack|pop_comments_gte %}
        {% if object.allow_thread %}
          {% include "comments/reply_button.html" with comment=object %}
        {% endif %}
      {% endfor %}
    {% endif %}

  {% endfor %}

  {% if is_paginated %}
    {% include "comments/pagination.html" %}
  {% endif %}
</div>
