{% extends 'forum/master.twig' %}
{% from 'macros.twig' import avatar %}
{% from 'forum/macros.twig' import forum_header %}

{% set title = 'Forum Leaderboard » ' ~ leaderboard_name %}
{% set canonical_url = url('forum-leaderboard', {
    'id': leaderboard_id,
    'mode': '',
}) %}

{% block content %}
    {{ forum_header(title, [], false, canonical_url, [
        {
            'html': '<i class="fab fa-markdown fa-fw"></i> Markdown',
            'url': url('forum-leaderboard', {'id': leaderboard_id, 'mode': 'markdown'}),
            'display': leaderboard_mode != 'markdown',
        },
        {
            'html': '<i class="fas fa-table fa-fw"></i> Table',
            'url': url('forum-leaderboard', {'id': leaderboard_id}),
            'display': leaderboard_mode == 'markdown',
        },
    ]) }}

    <div class="container forum__leaderboard__categories">
        <a href="{{ url('forum-leaderboard', {'mode': leaderboard_mode}) }}" class="forum__leaderboard__category{% if leaderboard_id == '' %} forum__leaderboard__category--active{% endif %}">All Time</a>
    </div>

    <div class="container forum__leaderboard__categories">
        {% for id, name in leaderboard_years %}
            <a href="{{ url('forum-leaderboard', {'id': id, 'mode': leaderboard_mode}) }}" class="forum__leaderboard__category{% if leaderboard_id == id %} forum__leaderboard__category--active{% endif %}">{{ name }}</a>
        {% endfor %}
    </div>

    <div class="container forum__leaderboard__categories">
        {% for id, name in leaderboard_months %}
            <a href="{{ url('forum-leaderboard', {'id': id, 'mode': leaderboard_mode}) }}" class="forum__leaderboard__category{% if leaderboard_id == id %} forum__leaderboard__category--active{% endif %}">{{ name }}</a>
        {% endfor %}
    </div>

    {% if leaderboard_mode == 'markdown' %}
        <textarea class="input__textarea forum__leaderboard__markdown">{{ leaderboard_markdown }}</textarea>
    {% else %}
        {% for ranking in leaderboard_data %}
            <div class="container forum__leaderboard__user forum__leaderboard__user--rank-{{ ranking.position }}">
                <a href="{{ url('user-profile', {'user': ranking.user.id|default()}) }}" class="forum__leaderboard__user__background"></a>
                <div class="forum__leaderboard__user__content">
                    <div class="forum__leaderboard__user__rank">{{ ranking.position|number_format }}</div>
                    <div class="forum__leaderboard__user__avatar">{{ avatar(ranking.user.id|default(), ranking.position == 1 ? 50 : 40, ranking.user.name|default('Deleted User')) }}</div>
                    <div class="forum__leaderboard__user__username">{{ ranking.user.name|default('Deleted User') }}</div>
                    <div class="forum__leaderboard__user__posts">{{ ranking.postsCount|number_format }} post{{ ranking.postsCount == 1 ? '' : 's' }}</div>
                </div>
            </div>
        {% endfor %}
    {% endif %}
{% endblock %}
