{% extends 'layouts/admin.html.twig' %}

{% block title %}Admin — {{ site.name }}{% endblock %}

{% block admin_content %}
    <section class="page-header">
        <h1>Dashboard</h1>
        <p class="muted">Forum overview</p>
    </section>

    <section class="admin-stats" aria-label="Forum statistics">
        <div class="admin-stat-card">
            <span class="admin-stat-value">{{ post_count }}</span>
            <span class="admin-stat-label">Posts</span>
        </div>
        <div class="admin-stat-card">
            <span class="admin-stat-value">{{ topic_count }}</span>
            <span class="admin-stat-label">Topics</span>
        </div>
        <a class="admin-stat-card admin-stat-card--link" href="/admin/users">
            <span class="admin-stat-value">{{ user_count }}</span>
            <span class="admin-stat-label">Users</span>
        </a>
        <a class="admin-stat-card admin-stat-card--link" href="/admin/boards">
            <span class="admin-stat-value">{{ board_count }}</span>
            <span class="admin-stat-label">Boards</span>
        </a>
        <a class="admin-stat-card admin-stat-card--link{% if open_reports %} admin-stat-card--alert{% endif %}" href="/admin/reports">
            <span class="admin-stat-value">{{ open_reports }}</span>
            <span class="admin-stat-label">Open reports</span>
        </a>
        <a class="admin-stat-card admin-stat-card--link" href="/admin/audit">
            <span class="admin-stat-value">{{ audit_log_count }}</span>
            <span class="admin-stat-label">Audit log entries</span>
        </a>
        {% if security_log_summary is defined %}
            <a class="admin-stat-card admin-stat-card--link{% if security_log_summary.count %} admin-stat-card--alert{% endif %}" href="{{ security_log_summary.view_url }}">
                <span class="admin-stat-value">{{ security_log_summary.count }}</span>
                <span class="admin-stat-label">Login failures</span>
                <span class="admin-stat-hint muted">Last {{ security_log_summary.sample_lines }} log lines</span>
            </a>
        {% endif %}
        <a class="admin-stat-card admin-stat-card--link{% if pending_approval %} admin-stat-card--alert{% endif %}" href="/admin/approval">
            <span class="admin-stat-value">{{ pending_approval }}</span>
            <span class="admin-stat-label">Pending approval</span>
        </a>
        <a class="admin-stat-card admin-stat-card--link{% if quarantine_count %} admin-stat-card--alert{% endif %}" href="/admin/quarantine">
            <span class="admin-stat-value">{{ quarantine_count|default(0) }}</span>
            <span class="admin-stat-label">Quarantined</span>
        </a>
    </section>

    {% if system_info is defined %}
        <section class="admin-system-panel" aria-label="System status">
            <h2 class="admin-system-heading">System</h2>
            <dl class="admin-system-grid">
                <div class="admin-system-item">
                    <dt>Database</dt>
                    <dd>
                        {{ system_info.database.total_label }}
                        <span class="muted">({{ system_info.database.detail_label }})</span>
                        · {{ system_info.database.journal_mode|upper }}
                    </dd>
                </div>
                <div class="admin-system-item">
                    <dt>Guest cache</dt>
                    <dd>{{ system_info.guest_cache.label }}</dd>
                </div>
                <div class="admin-system-item">
                    <dt>Last cron</dt>
                    <dd>
                        {% if system_info.cron.hourly.ago %}
                            hourly · {{ system_info.cron.hourly.ago }}
                        {% else %}
                            hourly · never
                        {% endif %}
                        ·
                        {% if system_info.cron.daily.ago %}
                            daily · {{ system_info.cron.daily.ago }}
                        {% else %}
                            daily · never
                        {% endif %}
                        ·
                        {% if system_info.cron.weekly.ago %}
                            weekly · {{ system_info.cron.weekly.ago }}
                        {% else %}
                            weekly · never
                        {% endif %}
                    </dd>
                </div>
                <div class="admin-system-item">
                    <dt>Mail</dt>
                    <dd{% if system_info.mail.alert %} class="admin-system-alert"{% endif %}>{{ system_info.mail.label }}</dd>
                </div>
            </dl>
        </section>
    {% endif %}

    {% if version_info is defined %}
        <section class="admin-version-panel" aria-label="Latch version">
            <div class="admin-version-main">
                <span class="admin-version-label">Installed</span>
                <span class="admin-version-value">{{ version_info.installed }}</span>
                {% if version_info.tree %}
                    <span class="admin-version-sep muted">·</span>
                    <span class="admin-version-label">Tree</span>
                    <span class="admin-version-value">{{ version_info.tree }}</span>
                {% endif %}
                <span class="badge admin-version-badge admin-version-badge--{{ version_info.status }}">{{ version_info.status_label }}</span>
            </div>
            {% if version_info.git %}
                <p class="muted admin-version-git">Git <code>{{ version_info.git }}</code></p>
            {% endif %}
        </section>
    {% endif %}
{% endblock %}