{% extends "base.html" %}
{% block extra_head %}
<link rel="stylesheet" href="{{ static_url('/static/css/feed.css') }}">
{% endblock %}
{% block content %}
<div class="leaderboard-page">
    <aside class="community-stats" aria-label="Community statistics">
        <h3>Community</h3>
        <div class="stat-row">
            <span class="label">Total Members</span>
            <span class="value">{{ total_members }}</span>
        </div>
        <div class="stat-row">
            <span class="label">Posts Today</span>
            <span class="value">{{ posts_today }}</span>
        </div>
        <div class="stat-row">
            <span class="label">Total Projects</span>
            <span class="value">{{ total_projects }}</span>
        </div>
        <div class="stat-row">
            <span class="label">Total Gists</span>
            <span class="value">{{ total_gists }}</span>
        </div>
        <div class="top-authors-section">
            <h3 class="top-authors-title">Top Authors</h3>
            {% for author in top_authors %}
            <div class="stat-row">
                <span class="label">
                    {% set _user = author %}{% set _size = 20 %}{% set _size_class = "xs" %}{% include "_avatar_link.html" %}
                    {% set _user = author %}{% set _class = "top-author-name" %}{% include "_user_link.html" %}
                </span>
                <span class="value">{{ author.get('stars', 0) }}</span>
            </div>
            {% else %}
            <div class="no-authors-msg">No top authors yet</div>
            {% endfor %}
        </div>
    </aside>

    <div class="leaderboard-main">
        <div class="leaderboard-header">
            <h1>Leaderboard</h1>
            {% if user_rank %}
            <span class="leaderboard-you">Your rank: #{{ user_rank }}</span>
            {% endif %}
        </div>
        <p class="leaderboard-intro">Ranked by total stars earned across posts, projects, and gists.</p>

        <ol class="leaderboard-list">
            {% for entry in entries %}
            <li class="leaderboard-row card-link-host{% if is_self(user, entry['uid']) %} leaderboard-row-self{% endif %}">
                {% set _href = "/profile/" ~ entry['username'] %}
                {% set _label = entry['username'] %}
                {% include "_card_link.html" %}
                <span class="leaderboard-rank">#{{ entry['rank'] }}</span>
                {% set _user = entry %}{% set _size = 32 %}{% set _size_class = "sm" %}{% include "_avatar_link.html" %}
                {% set _user = entry %}{% set _class = "leaderboard-name" %}{% include "_user_link.html" %}
                <span class="leaderboard-level">Level {{ entry.get('level', 1) }}</span>
                <span class="leaderboard-stars">{{ entry['stars'] }} <span class="leaderboard-star-icon" aria-hidden="true">&#x2605;</span></span>
            </li>
            {% else %}
            <li class="leaderboard-empty">No ranked contributors yet. Earn stars on your posts, projects, and gists to appear here.</li>
            {% endfor %}
        </ol>
    </div>

    <aside class="feed-right" aria-label="Featured news">
        <div class="featured-news">
            <h3>Featured</h3>
            {% for article in featured_news %}
            <a class="featured-news-item" href="/news/{{ article['slug'] }}">
                <span class="featured-news-title">{{ render_title(article['title']) }}</span>
                <span class="featured-news-meta">{{ article['source_name'] }}{% if article['time_ago'] %} &middot; {{ dt_ago(article['synced_at']) if article['synced_at'] else article['time_ago'] }}{% endif %}</span>
            </a>
            {% else %}
            <div class="no-authors-msg">No featured articles yet</div>
            {% endfor %}
        </div>
    </aside>
</div>
{% endblock %}
