{% extends 'home/master.twig' %}
{% from 'macros.twig' import container_title, avatar %}

{% set canonical_url = '/' %}

{% set landing_stats = [
    {
        icon: 'fas fa-users fa-fw',
        name: 'members',
        value: statistics['users:active']|number_format,
    },
    {
        icon: 'fas fa-user-check fa-fw',
        name: 'online',
        value: statistics['users:online:recent']|number_format,
    },
    {
        icon: 'fas fa-user-clock fa-fw',
        name: 'active (24 hr)',
        value: statistics['users:online:today']|number_format,
    },
    {
        icon: 'fas fa-list fa-fw',
        name: 'topics',
        value: statistics['forum:topics:visible']|number_format,
    },
    {
        icon: 'fas fa-comments fa-fw',
        name: 'posts',
        value: statistics['forum:posts:visible']|number_format,
    },
    {
        icon: 'fas fa-comment-dots fa-fw',
        name: 'comments',
        value: statistics['comments:posts:visible']|number_format,
    },
] %}

{% set header_menu = msz_header_menu() %}

{% block main_header %}
    <div class="landingv2-header">
        <div class="landingv2-header-background"></div>
        <div class="landingv2-header-content">
            <div class="landingv2-welcome">
                <a href="{{ url('index') }}">
                    <img src="/images/landing-logo.png" alt="{{ globals.site_info.name }}">
                </a>
            </div>

            <div class="landingv2-header-menu">
                {% for item in header_menu[1:] %}
                    <a href="{{ item.url }}" class="landingv2-header-menu-link">{{ item.title }}</a>
                {% endfor %}

                <a href="{{ url('auth-login') }}" class="landingv2-header-menu-link landingv2-auth-link landingv2-auth-link-login">
                    <div><i class="fas fa-sign-in-alt fa-fw"></i> Log in</div>
                </a>
                <a href="{{ url('auth-register') }}" class="landingv2-header-menu-link landingv2-auth-link landingv2-auth-link-register">
                    <div><i class="fas fa-user-plus fa-fw"></i> Register</div>
                </a>
            </div>
        </div>
    </div>
{% endblock %}

{% block main_footer %}
    <footer class="landingv2-footer">
        <div class="landingv2-footer-background"></div>
        <div class="landingv2-footer-wrapper">
            <div class="landingv2-footer-navigation">
                {% for item in header_menu[0].menu %}
                    <div>
                        <a href="{{ item.url }}">{{ item.title }}</a>
                    </div>
                {% endfor %}
            </div>
            <div class="landingv2-footer-copyright">
                <div class="landingv2-footer-copyright-line">
                    <a href="https://flash.moe" target="_blank" rel="noreferrer noopener">flashwave</a> 2013-{{ ''|date('Y') }}
                </div>
                <div class="landingv2-footer-copyright-line">
{% set git_branch = git_branch() %}
{% if git_branch != 'HEAD' %}
                    <a href="https://github.com/flashwave/misuzu/tree/{{ git_branch }}" target="_blank" rel="noreferrer noopener">{{ git_branch }}</a>
{% else %}
{% set git_tag = git_tag() %}
                    <a href="https://github.com/flashwave/misuzu/tree/{{ git_tag }}" target="_blank" rel="noreferrer noopener">{{ git_tag }}</a>
{% endif %}
                    # <a href="https://github.com/flashwave/misuzu/commit/{{ git_commit_hash(true) }}" target="_blank" rel="noreferrer noopener">{{ git_commit_hash() }}</a>
                </div>
{% if globals.display_timings_info %}
                <div class="landingv2-footer-copyright-line">
                    {{ sql_query_count()|number_format }} queries / {{ (startup_time() - startup_time(constant('MSZ_TPL_RENDER')))|number_format(5) }} load / {{ startup_time(constant('MSZ_TPL_RENDER'))|number_format(5) }} template / {{ startup_time()|number_format(5) }} total
                </div>
{% endif %}
            </div>
        </div>
    </footer>
{% endblock %}

{% block content %}
    <div class="landingv2-content">
        <div class="landingv2-stats">
{% for stat in landing_stats %}
            <div class="landingv2-stat">
                <div class="landingv2-stat-icon">
                    <i class="{{ stat.icon }}"></i>
                </div>
                <div class="landingv2-stat-value">
                    <span class="landingv2-stat-value-num">{{ stat.value }}</span> {{ stat.name }}
                </div>
            </div>
{% endfor %}
        </div>

        <div class="landingv2-forum">
            <div class="landingv2-forum-topics landingv2-forum-topics-popular">
                {{ container_title('<i class="fas fa-star fa-fw"></i> Popular Topics') }}
                <div class="landingv2-forum-topics-list">
{% for topic in forum_popular %}
                    <div class="landingv2-forum-topic">
                        <a href="{{ url('forum-topic', {'topic': topic.topic_id}) }}" class="landingv2-forum-topic-link"></a>
                        <div class="landingv2-forum-topic-info">
                            <div class="landingv2-forum-topic-info-icon">
                                <i class="{{ topic.forum_icon|default('fas fa-comments fa-fw') }}"></i>
                            </div>
                            <div class="landingv2-forum-topic-info-details">
                                <div class="landingv2-forum-topic-info-details-title">
                                    {{ topic.topic_title }}
                                </div>
                            </div>
                            <div class="landingv2-forum-topic-info-stats">
                                <div class="landingv2-forum-topic-info-stats-posts">{{ topic.topic_count_posts|number_format }}</div>
                                <div class="landingv2-forum-topic-info-stats-views">{{ topic.topic_count_views|number_format }}</div>
                            </div>
                        </div>
                    </div>
{% endfor %}
                </div>
            </div>
            <div class="landingv2-forum-topics landingv2-forum-topics-active">
                {{ container_title('<i class="fas fa-wind fa-fw"></i> Active Topics') }}
                <div class="landingv2-forum-topics-list">
{% for topic in forum_active %}
                    <div class="landingv2-forum-topic">
                        <a href="{{ url('forum-post', {'post': topic.latest_post_id}) }}" class="landingv2-forum-topic-link"></a>
                        <div class="landingv2-forum-topic-info">
                            <div class="landingv2-forum-topic-info-icon">
                                <i class="{{ topic.forum_icon|default('fas fa-comments fa-fw') }}"></i>
                            </div>
                            <div class="landingv2-forum-topic-info-details">
                                <div class="landingv2-forum-topic-info-details-title">
                                    {{ topic.topic_title }}
                                </div>
                            </div>
                            <div class="landingv2-forum-topic-info-stats">
                                <div class="landingv2-forum-topic-info-stats-posts">{{ topic.topic_count_posts|number_format }}</div>
                                <div class="landingv2-forum-topic-info-stats-views">{{ topic.topic_count_views|number_format }}</div>
                            </div>
                        </div>
                    </div>
{% endfor %}
                </div>
            </div>
        </div>

        <div class="landingv2-news">
{% for post in featured_news %}
            <div class="landingv2-news-post markdown">
                <h1>{{ post.title }}</h1>
                <p>{{ post.firstParagraph|parse_text(2)|raw }}</p>
                <div class="landingv2-news-post-options">
                    <a href="{{ url('news-post', {'post': post.id}) }}" class="landingv2-news-post-option">Continue reading</a>
                    | <time datetime="{{ post.createdTime|date('c') }}" title="{{ post.createdTime|date('r') }}">{{ post.createdTime|time_format }}</time>
                </div>
            </div>
{% endfor %}
        </div>

{% if online_users|length > 0 %}
        <div class="landingv2-online">
            {{ container_title('<i class="fas fa-users fa-fw"></i> Currently Online') }}
            <div class="landingv2-online-users">
                <div class="landingv2-online-inner">
                    {% for user in online_users %}
                        <a href="{{ url('user-profile', {'user': user.id}) }}" class="landingv2-online-avatar" title="{{ user.name }}">
                            {{ avatar(user.id, 50, user.name) }}
                        </a>
                    {% endfor %}
                </div>
            </div>
        </div>
{% endif %}
    </div>

{% if linked_data is not null %}
    <script type="application/ld+json">{{ linked_data|json_encode|raw }}</script>
{% endif %}
{% endblock %}

