{% load cache pagination_tags jmbo_template_tags foundry_tags i18n %}

<div class="comment-list">

<script type="text/javascript">
$(document).ready(function(){
    $(document).on('click', 'a.comment-reply', function(event){
        event.preventDefault();
        // Update hidden input, focus comment form
        $('#id_in_reply_to').val($(this).attr('comment_id'));
        var area = $('#id_comment');
        var creator = $(this).attr('creator');
        if (creator)
            area.val('@' + creator + ': ');
        else
            area.val('');
        area.focus();
    });
});
</script>

{% with request.REQUEST.paginate_by|default:20|add:0 as paginate_by %}
{% with request.REQUEST.paginate_offset|default:0|add:0 as paginate_offset %}

    <div class="foundry-container foundry-comments-list">

        {% autopaginate comment_list paginate_by paginate_offset %}
        <div class="items">
            {% for comment in comment_list %}
                {% get_can_report_comment comment as 'can_report_comment' %}
                {% jmbocache 3600 'comment-list-comment' comment.id can_report_comment request.user.id %}
                <div id="c{{ comment.id }}" class="item {% if comment.in_reply_to_id %}child{% endif %}">
                    {% if comment.creator %}
                    <div class="image">
                        <a href="{% url "user-detail" comment.creator.username %}">
                        {% if comment.creator.image %}
                            <img src="{{ comment.creator.get_thumbnail_url }}" />
                        {% else %}
                            <img src="{{ STATIC_URL }}/images/anonymous.png" />
                        {% endif %}
                        </a>
                    </div>
                    {% endif %}
                    <div class="meta">
                        <div class="byline">{% humanize_time_diff comment.submit_date '' %}</div>
                    </div>
                    <div class="actions">
                        <!-- todo: Need can comment test -->
                        <div class="reply">
                            {% with request.POST.next|default:request.META.PATH_INFO as next %}
                                <a href="{% url "comment-reply-form" %}?content_type_id={{ comment.content_type_id }}&oid={{ comment.object_pk }}&next={{ next }}&paginate_by={{ paginate_by }}"
                                   class="comment-reply"
                                   comment_id="{{ comment.id }}"
                                   creator="{{ comment.creator.username }}"
                                   rel="nofollow">{% trans "Reply" %}
                                </a>
                            {% endwith %}
                        </div>
                        {% if can_report_comment %}
                            {% with request.POST.next|default:request.META.PATH_INFO as next %}
                                <a href="{% url "report-comment" comment.id %}?next={{ next|add:"?"|add:request.META.QUERY_STRING|urlencode }}" class="report" rel="nofollow">{% trans "Report" %}</a>
                            {% endwith %}
                        {% else %}
                            {% if request.user.is_authenticated %}
                                {% trans "Reported" %}
                            {% endif %}
                        {% endif %}
                    </div>
                    <div class="comment">
                        <span class="creator">{{ comment.user.username|default:comment.name }}:</span> {{ comment.comment|urlize }}
                    </div>
                </div>
                {% endjmbocache %}
            {% endfor %}
            <div
                class="comment-list-placeholder"
                content_type_id="{{ object.content_type_id }}"
                oid="{{ object.id }}"
                last_comment_id="{{ foundry_last_comment_id }}">
            </div>
        </div>

        {% paginate %}

    </div>

{% endwith %}
{% endwith %}

</div>
