{% extends "administration/base.html" %}

{% load i18n %}

{% block content %}
<section class="pf-c-page__main-section pf-m-light">
    <div class="pf-c-content">
        <h1>{% trans 'System Overview' %}</h1>
    </div>
</section>
<section class="pf-c-page__main-section">
    <div class="pf-l-gallery pf-m-gutter">
        <a href="{% url 'passbook_admin:applications' %}" class="pf-c-card pf-m-hoverable pf-m-compact">
            <div class="pf-c-card__head">
                <div class="pf-c-card__head-main">
                    <i class="pf-icon pf-icon-applications"></i> {% trans 'Applications' %}
                </div>
            </div>
            <div class="pf-c-card__body">
                <i class="pf-icon pf-icon-ok"></i> {{ application_count }}
            </div>
        </a>

        <a href="{% url 'passbook_admin:sources' %}" class="pf-c-card pf-m-hoverable pf-m-compact">
            <div class="pf-c-card__head">
                <div class="pf-c-card__head-main">
                    <i class="pf-icon pf-icon-middleware"></i> {% trans 'Sources' %}
                </div>
            </div>
            <div class="pf-c-card__body">
                <i class="pf-icon pf-icon-ok"></i> {{ source_count }}
            </div>
        </a>

        <a href="{% url 'passbook_admin:providers' %}" class="pf-c-card pf-m-hoverable pf-m-compact">
            <div class="pf-c-card__head">
                <div class="pf-c-card__head-main">
                    <i class="pf-icon pf-icon-plugged"></i> {% trans 'Providers' %}
                </div>
            </div>
            <div class="pf-c-card__body">
                {% if providers_without_application.exists %}
                <i class="pf-icon pf-icon-warning-triangle"></i> {{ provider_count }}
                <p>{% trans 'Warning: At least one Provider has no application assigned.' %}</p>
                {% else %}
                <i class="pf-icon pf-icon-ok"></i> {{ provider_count }}
                {% endif %}
            </div>
        </a>

        <a href="{% url 'passbook_admin:stages' %}" class="pf-c-card pf-m-hoverable pf-m-compact">
            <div class="pf-c-card__head">
                <div class="pf-c-card__head-main">
                    <i class="pf-icon pf-icon-plugged"></i> {% trans 'Stages' %}
                </div>
            </div>
            <div class="pf-c-card__body">
                {% if factor_count < 1 %}
                <i class="pficon-error-circle-o"></i> {{ factor_count }}
                <p>{% trans 'No Stages configured. No Users will be able to login.' %}"></p>
                {% else %}
                <i class="pf-icon pf-icon-ok"></i> {{ factor_count }}
                {% endif %}
            </div>
        </a>

        <a href="{% url 'passbook_admin:policies' %}" class="pf-c-card pf-m-hoverable pf-m-compact">
            <div class="pf-c-card__head">
                <div class="pf-c-card__head-main">
                    <i class="pf-icon pf-icon-infrastructure"></i> {% trans 'Policies' %}
                </div>
            </div>
            <div class="pf-c-card__body">
                {% if policies_without_binding %}
                <i class="pf-icon pf-icon-warning-triangle"></i> {{ policy_count }}
                <p>{% trans 'Policies without binding exist.' %}</p>
                {% else %}
                <i class="pf-icon pf-icon-ok"></i> {{ policy_count }}
                {% endif %}
            </div>
        </a>

        <a href="{% url 'passbook_admin:invitations' %}" class="pf-c-card pf-m-hoverable pf-m-compact">
            <div class="pf-c-card__head">
                <div class="pf-c-card__head-main">
                    <i class="pf-icon pf-icon-migration"></i> {% trans 'Invitation' %}
                </div>
            </div>
            <div class="pf-c-card__body">
                <i class="pf-icon pf-icon-ok"></i> {{ invitation_count }}
            </div>
        </a>

        <a href="{% url 'passbook_admin:users' %}" class="pf-c-card pf-m-hoverable pf-m-compact">
            <div class="pf-c-card__head">
                <div class="pf-c-card__head-main">
                    <i class="pf-icon pf-icon-user"></i> {% trans 'Users' %}
                </div>
            </div>
            <div class="pf-c-card__body">
                <i class="pf-icon pf-icon-ok"></i> {{ user_count }}
            </div>
        </a>

        <div class="pf-c-card pf-m-hoverable pf-m-compact">
            <div class="pf-c-card__head">
                <div class="pf-c-card__head-main">
                    <i class="pf-icon pf-icon-bundle"></i> {% trans 'Version' %}
                </div>
            </div>
            <div class="pf-c-card__body">
                <i class="pf-icon pf-icon-ok"></i> {{ version }}
            </div>
        </div>

        <div class="pf-c-card pf-m-hoverable pf-m-compact">
            <div class="pf-c-card__head">
                <div class="pf-c-card__head-main">
                    <i class="pf-icon pf-icon-server"></i> {% trans 'Workers' %}
                </div>
            </div>
            <div class="pf-c-card__body">
                {% if worker_count < 1 %}
                <i class="pf-icon pf-icon-warning-triangle"></i> {{ worker_count }}
                <p>{% trans 'No workers connected.' %}</p>
                {% else %}
                <i class="pf-icon pf-icon-ok"></i> {{ worker_count }}
                {% endif %}
            </div>
        </div>

        <a class="pf-c-card pf-m-hoverable pf-m-compact" data-target="modal" data-modal="clearCacheModalRoot">
            <div class="pf-c-card__head">
                <div class="pf-c-card__head-main">
                    <i class="pf-icon pf-icon-server"></i> {% trans 'Cached Policies' %}
                </div>
            </div>
            <div class="pf-c-card__body">
                {% if cached_policies < 1 %}
                <i class="pf-icon pf-icon-warning-triangle"></i> {{ cached_policies }}
                <p>{% trans 'No policies cached. Users may experience slow response times.' %}</p>
                {% else %}
                <i class="pf-icon pf-icon-ok"></i> {{ cached_policies }}
                {% endif %}
            </div>
        </a>
    </section>
</div>
<div class="pf-c-backdrop" id="clearCacheModalRoot" hidden>
    <div class="pf-l-bullseye">
        <div class="pf-c-modal-box pf-m-sm" role="dialog">
            <button data-modal-close class="pf-c-button pf-m-plain" type="button" aria-label="Close dialog">
                <i class="fas fa-times" aria-hidden="true"></i>
            </button>
            <h1 class="pf-c-title pf-m-2xl" id="modal-title">{% trans 'Clear Cache' %}?</h1>
            <div class="pf-c-modal-box__body" id="modal-description">
                <form method="post" id="clearForm">
                    {% csrf_token %}
                    <input type="hidden" name="clear">
                    <p>
                        {% blocktrans %}
                        Are you sure you want to clear the cache? This includes all user sessions and all cached Policy results.
                        {% endblocktrans %}
                    </p>
                    <h3>
                        {% blocktrans %}
                        This will also log you out.
                        {% endblocktrans %}
                    </h3>
                </form>
            </div>
            <footer class="pf-c-modal-box__footer pf-m-align-left">
                <button form="clearForm" class="pf-c-button pf-m-primary" type="submit">{% trans 'Clear' %}</button>
                <button data-modal-close class="pf-c-button pf-m-link" type="button">{% trans 'Cancel' %}</button>
            </footer>
        </div>
    </div>
</div>
{% endblock %}