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

{% set warns_pagination = pagination(manage_warns_pagination, 'manage-users-warnings', {'user': manage_warns_filter_user.id|default(0)}) %}
{% set warns_filtering = manage_warns_filter_user is not null %}

{% block manage_content %}
    <div class="container manage__warnings">
        {{ container_title('<i class="fas fa-exclamation-circle fa-fw"></i> Warnings') }}

        <div class="manage__description">
            List of user warnings.
            {% if not warns_filtering %}Filter by a user to issue a new warning.{% endif %}
        </div>

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

        {% if warns_filtering %}
            <div class="manage__warnings__actions">
                <a href="{{ url('manage-users-warning', {'user': manage_warns_filter_user.id}) }}" class="input__button">Issue new Warning</a>
            </div>
        {% endif %}

        <div class="manage__warnings__list">
        {% for warn in manage_warns %}
            <div class="manage__warnings__item">
                <div class="manage__warnings__item__header">
                    <div class="manage__warnings__item__attributes">
                        {% if warn.mod is not null %}
                            <div class="manage__warnings__item__attribute manage__warnings__item__author" style="--user-colour: {{ warn.mod_colour }}">
                                <div class="manage__warnings__item__author__prefix">Issued by</div>
                                <div class="manage__warnings__item__author__avatar">
                                    <a href="{{ url('user-profile', {'user': warn.mod.id}) }}">{{ avatar(warn.mod.id, 20, warn.mod.name) }}</a>
                                </div>
                                <div class="manage__warnings__item__author__name">
                                    <a href="{{ url('user-profile', {'user': warn.mod.id}) }}">{{ warn.mod.name }}</a>
                                </div>
                            </div>
                        {% endif %}
                        <div class="manage__warnings__item__attribute manage__warnings__item__created">
                            <div class="manage__warnings__item__created__icon"><i class="fas fa-clock"></i></div>
                            <div class="manage__warnings__item__created__time">
                                <time datetime="{{ warn.info.createdTime|date('c') }}" title="{{ warn.info.createdTime|date('r') }}">{{ warn.info.createdTime|time_format }}</time>
                            </div>
                        </div>
                        <div class="manage__warnings__item__attribute manage__warnings__item__user" style="--user-colour: {{ warn.user_colour }}">
                            <div class="manage__warnings__item__user__prefix">Subject</div>
                            <div class="manage__warnings__item__user__avatar">
                                <a href="{{ url('manage-user', {'user': warn.user.id}) }}">{{ avatar(warn.user.id, 20, warn.user.name) }}</a>
                            </div>
                            <div class="manage__warnings__item__user__name">
                                <a href="{{ url('manage-user', {'user': warn.user.id}) }}">{{ warn.user.name }}</a>
                            </div>
                            {% if not warns_filtering %}
                                <div class="manage__warnings__item__user__filter">
                                    <a href="{{ url('manage-users-warnings', {'user': warn.user.id}) }}">Filter</a>
                                </div>
                            {% endif %}
                        </div>
                    </div>
                    <div class="manage__warnings__item__actions">
                        <a href="{{ url('manage-users-warning-delete', { warning: warn.info.id, csrf: csrf_token() }) }}" title="Remove" class="input__button input__button--autosize input__button--destroy manage__warnings__item__action" onclick="return confirm('Are you sure?');"><i class="fas fa-times fa-fw"></i></a>
                    </div>
                </div>
                <div class="manage__warnings__item__reason">
                    {% for line in warn.info.bodyLines %}
                        <p>{{ line }}</p>
                    {% endfor %}
                </div>
            </div>
        {% endfor %}
        </div>

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