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

{% set bans_pagination = pagination(manage_bans_pagination, 'manage-users-bans', {'user': manage_bans_filter_user.id|default(0)}) %}
{% set bans_filtering = manage_bans_filter_user is not null %}

{% block manage_content %}
    <div class="container manage__bans">
        {{ container_title('<i class="fas fa-ban fa-fw"></i> Bans') }}

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

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

        {% if bans_filtering %}
            <div class="manage__bans__actions">
                <a href="{{ url('manage-users-ban', {'user': manage_bans_filter_user.id}) }}" class="input__button">Issue new Ban</a>
            </div>
        {% endif %}

        <div class="manage__bans__list">
        {% for ban in manage_bans %}
            <div class="manage__bans__item">
                <div class="manage__bans__item__header">
                    <div class="manage__bans__item__attributes">
                        {% if ban.mod is not null %}
                            <div class="manage__bans__item__attribute manage__bans__item__author" style="--user-colour: {{ ban.mod_colour }}">
                                <div class="manage__bans__item__author__prefix">Issued by</div>
                                <div class="manage__bans__item__author__avatar">
                                    <a href="{{ url('user-profile', {'user': ban.mod.id}) }}">{{ avatar(ban.mod.id, 20, ban.mod.name) }}</a>
                                </div>
                                <div class="manage__bans__item__author__name">
                                    <a href="{{ url('user-profile', {'user': ban.mod.id}) }}">{{ ban.mod.name }}</a>
                                </div>
                            </div>
                        {% endif %}
                        <div class="manage__bans__item__attribute manage__bans__item__created">
                            <div class="manage__bans__item__created__icon"><i class="fas fa-clock"></i></div>
                            <div class="manage__bans__item__created__time">
                                <time datetime="{{ ban.info.createdTime|date('c') }}" title="{{ ban.info.createdTime|date('r') }}">{{ ban.info.createdTime|time_format }}</time>
                            </div>
                        </div>
                        {% if ban.info.isPermanent %}
                            <div class="manage__bans__item__attribute manage__bans__item__permanent">
                                <div class="manage__bans__item__permanent__icon"><i class="fas fa-dumpster"></i></div>
                                <div class="manage__bans__item__permanent__time">
                                    PERMANENT
                                </div>
                            </div>
                        {% else %}
                            <div class="manage__bans__item__attribute manage__bans__item__expires">
                                <div class="manage__bans__item__expires__icon"><i class="fas fa-stopwatch"></i></div>
                                <div class="manage__bans__item__expires__time" title="{{ ban.info.expiresTime|date('r') }}">
                                    {% if ban.info.isActive %}
                                        <span>{{ ban.info.remainingString }} remaining</span>
                                    {% else %}
                                        <span>{{ ban.info.durationString }}</span>
                                    {% endif %}
                                </div>
                                {% if ban.info.isActive %}
                                    <div class="manage__bans__item__expires__status manage__bans__item__expires__status--active">
                                        <span>active</span>
                                    </div>
                                {% else %}
                                    <div class="manage__bans__item__expires__status manage__bans__item__expires__status--expired">
                                        <span>expired</span>
                                    </div>
                                {% endif %}
                            </div>
                        {% endif %}
                        <div class="manage__bans__item__attribute manage__bans__item__user" style="--user-colour: {{ ban.user_colour }}">
                            <div class="manage__bans__item__user__prefix">Subject</div>
                            <div class="manage__bans__item__user__avatar">
                                <a href="{{ url('manage-user', {'user': ban.user.id}) }}">{{ avatar(ban.user.id, 20, ban.user.name) }}</a>
                            </div>
                            <div class="manage__bans__item__user__name">
                                <a href="{{ url('manage-user', {'user': ban.user.id}) }}">{{ ban.user.name }}</a>
                            </div>
                            {% if not bans_filtering %}
                                <div class="manage__bans__item__user__filter">
                                    <a href="{{ url('manage-users-bans', {'user': ban.user.id}) }}">Filter</a>
                                </div>
                            {% endif %}
                        </div>
                    </div>
                    <div class="manage__bans__item__actions">
                        <a href="{{ url('manage-users-ban-delete', { ban: ban.info.id, csrf: csrf_token() }) }}" title="Revoke/Delete" class="input__button input__button--autosize input__button--destroy manage__bans__item__action" onclick="return confirm('Are you sure?');"><i class="fas fa-times fa-fw"></i></a>
                    </div>
                </div>
                {% if ban.info.hasPublicReason %}
                    <div class="manage__bans__item__reason">
                        <div class="manage__bans__item__reason__title">Reason displayed publicly and to the user themselves:</div>
                        <div class="manage__bans__item__reason__body">{{ ban.info.publicReason }}</div>
                    </div>
                {% else %}
                    <div class="manage__bans__item__reason">
                        <div class="manage__bans__item__reason__title">This ban does not display any reason.</div>
                    </div>
                {% endif %}
                {% if ban.info.hasPrivateReason %}
                    <div class="manage__bans__item__reason">
                        <div class="manage__bans__item__reason__title">Additional information for moderators:</div>
                        <div class="manage__bans__item__reason__body">{{ ban.info.privateReason }}</div>
                    </div>
                {% else %}
                    <div class="manage__bans__item__reason">
                        <div class="manage__bans__item__reason__title">This ban does not provide additional information for moderators.</div>
                    </div>
                {% endif %}
            </div>
        {% endfor %}
        </div>

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