{% import '@ChillPerson/AccompanyingCourse/Comment/macro_showItem.html.twig' as m %}

{% macro recordAction(comment) %}
    {% if is_granted('CHILL_MAIN_NOTIFICATION_COMMENT_EDIT', comment) %}
        <li>
            <a href="{{ chill_path_forward_return_path('chill_main_notification_show', {
                '_fragment': 'comment-' ~ comment.id,
                'edit': comment.id,
                'id': comment.notification.id
            }) }}" class="btn btn-edit" title="{{ 'Edit'|trans }}"
            ></a>
        </li>
    {% endif %}
{% endmacro %}

<div class="notification-comment-list my-5">
    <h2 class="chill-blue">{{ 'notification.comments_list'|trans }}</h2>

    {% if notification.comments|length > 0 %}
        <div class="flex-table">
            {% for comment in notification.comments %}

                {% if editedCommentForm is null or editedCommentId != comment.id %}
                    {{ m.show_comment(comment, {
                        'recordAction': _self.recordAction(comment)
                    }) }}
                {% else %}
                    <div class="item-bloc">
                        <div class="item-row row">
                            <a id="comment-{{ comment.id }}"></a>

                            {{ form_start(editedCommentForm) }}
                            {{ form_errors(editedCommentForm) }}
                            {{ form_widget(editedCommentForm.content) }}
                            {{ form_errors(editedCommentForm.content) }}
                            <input type="hidden" name="form" value="edit" />
                            <ul class="record_actions">
                                <li class="cancel">
                                    <a href="{{ chill_path_forward_return_path('chill_main_notification_show', {
                                        '_fragment': 'comment-' ~ comment.id,
                                        'id': notification.id }) }}" class="btn btn-cancel">
                                        {{ 'cancel'|trans }}
                                    </a>
                                </li>
                                <li>
                                    <button class="btn btn-save" type="submit">{{ 'Save'|trans }}</button>
                                </li>
                            </ul>
                            {{ form_end(editedCommentForm) }}

                        </div>
                    </div>
                {% endif %}

            {% endfor %}
        </div>
    {% else %}
        <span class="chill-no-data-statement">{{ 'No comments'|trans }}</span>
    {% endif %}

    {% if appendCommentForm is not null %}
        <div class="new-comment my-5">
            <h2 class="chill-blue mb-4">{{ 'Write a new comment'|trans }}</h2>

            {{ form_start(appendCommentForm) }}
            {{ form_errors(appendCommentForm) }}
            {{ form_widget(appendCommentForm.content) }}
            {{ form_errors(appendCommentForm.content) }}
            <input type="hidden" name="form" value="append" />
            <ul class="record_actions">
                <li>
                    <button class="btn btn-create" type="submit">{{ 'notification.append_comment'|trans }}</button>
                </li>
            </ul>
            {{ form_end(appendCommentForm) }}

        </div>
    {% endif %}
</div>
