{% extends 'manage/users/master.twig' %}
{% from 'macros.twig' import pagination, container_title, avatar %}

{% set notes_pagination = pagination(manage_notes_pagination, 'manage-users-notes', {'user': manage_notes_filter_user.id|default(0)}) %}
{% set notes_filtering = manage_notes_filter_user is not null %}

{% block manage_content %}
    <div class="container manage__notes">
        {{ container_title('<i class="fas fa-sticky-note fa-fw"></i> Moderator Notes') }}

        <div class="manage__description">
            Private moderator notes, can be used for anything you'd like to share internally.
            {% if not notes_filtering %}Filter by a user to create a new note.{% endif %}
        </div>

        {% if notes_pagination|trim|length > 0 %}
            <div class="manage__notes__pagination">
                {{ notes_pagination }}
            </div>
        {% endif %}

        {% if notes_filtering %}
            <div class="manage__notes__actions">
                <a href="{{ url('manage-users-note', {'user': manage_notes_filter_user.id}) }}" class="input__button">New Note</a>
            </div>
        {% endif %}

        <div class="manage__notes__list">
        {% for note in manage_notes %}
            <div class="manage__notes__item">
                <div class="manage__notes__item__header">
                    <div class="manage__notes__item__title"><a href="{{ url('manage-users-note', {'note': note.info.id}) }}">{{ note.info.title }}</a></div>
                    <div class="manage__notes__item__actions">
                        <a href="{{ url('manage-users-note', { note: note.info.id }) }}" title="View/Edit" class="input__button input__button--autosize manage__notes__item__action"><i class="fas fa-pen fa-fw"></i></a>
                        <a href="{{ url('manage-users-note-delete', { note: note.info.id, csrf: csrf_token() }) }}" title="Delete" class="input__button input__button--autosize input__button--destroy manage__notes__item__action" onclick="return confirm('Are you sure?');"><i class="fas fa-times fa-fw"></i></a>
                    </div>
                </div>
                <div class="manage__notes__item__attributes">
                    {% if note.author is not null %}
                        <div class="manage__notes__item__attribute manage__notes__item__author"{% if note.author_colour is not null %} style="--user-colour: {{ note.author_colour }}"{% endif %}>
                            <div class="manage__notes__item__author__prefix">Created by</div>
                            <div class="manage__notes__item__author__avatar">
                                <a href="{{ url('user-profile', {'user': note.author.id}) }}">{{ avatar(note.author.id, 20, note.author.name) }}</a>
                            </div>
                            <div class="manage__notes__item__author__name">
                                <a href="{{ url('user-profile', {'user': note.author.id}) }}">{{ note.author.name }}</a>
                            </div>
                        </div>
                    {% endif %}
                    <div class="manage__notes__item__attribute manage__notes__item__created">
                        <div class="manage__notes__item__created__icon"><i class="fas fa-clock"></i></div>
                        <div class="manage__notes__item__created__time">
                            <time datetime="{{ note.info.createdTime|date('c') }}" title="{{ note.info.createdTime|date('r') }}">{{ note.info.createdTime|time_format }}</time>
                        </div>
                    </div>
                    <div class="manage__notes__item__attribute manage__notes__item__user"{% if note.user_colour is not null %} style="--user-colour: {{ note.user_colour }}"{% endif %}>
                        <div class="manage__notes__item__user__prefix">Regarding</div>
                        <div class="manage__notes__item__user__avatar">
                            <a href="{{ url('manage-user', {'user': note.user.id}) }}">{{ avatar(note.user.id, 20, note.user.name) }}</a>
                        </div>
                        <div class="manage__notes__item__user__name">
                            <a href="{{ url('manage-user', {'user': note.user.id}) }}">{{ note.user.name }}</a>
                        </div>
                        {% if not notes_filtering %}
                            <div class="manage__notes__item__user__filter">
                                <a href="{{ url('manage-users-notes', {'user': note.user.id}) }}">Filter</a>
                            </div>
                        {% endif %}
                    </div>
                </div>
                {% if note.info.hasBody %}
                    <div class="manage__notes__item__body markdown">
                        {% if notes_filtering %}
                            {{ note.info.body|parse_text(2)|raw }}
                        {% else %}
                            {{ note.info.firstParagraph|parse_text(2)|raw }}
                        {% endif %}
                    </div>
                {% else %}
                    <div class="manage__notes__item__nobody">
                        This note has no additional content.
                    </div>
                {% endif %}
                {% if not notes_filtering and note.info.hasMoreParagraphs %}
                    <div class="manage__notes__item__continue">
                        <a href="{{ url('manage-users-note', {'note': note.info.id}) }}">Continue reading</a>
                    </div>
                {% endif %}
            </div>
        {% endfor %}
        </div>

        {% if notes_pagination|trim|length > 0 %}
            <div class="manage__notes__pagination">
                {{ notes_pagination }}
            </div>
        {% endif %}
    </div>
{% endblock %}
