{% extends 'orga/base.html' %}
{% load bootstrap4 %}
{% load i18n %}

{% block content %}

<h2>{% trans "Update check results" %}</h2>

{% if not gs.settings.update_check_enabled %}
    <div class="alert alert-warning">
        {% trans "Update checks are disabled." %}
    </div>
{% elif not gs.settings.update_check_last %}
    <div class="alert alert-info">
        {% trans "No update check has been performed yet since the last update of this installation. Update checks are performed on a daily basis if your cronjob is set up properly." %}
    </div>
    <form action="" method="post">
        {% csrf_token %}
        <p class="d-flex">
            <button type="submit" name="trigger" value="1" class="btn btn-outline-info ml-auto">
                <i class="fa fa-refresh mr-2"></i>
                {% trans "Check for updates now" %}
            </button>
        </p>
    </form>
{% elif "error" in gs.settings.update_check_result %}
    <div class="alert alert-danger">
        {% trans "The last update check was not successful." %}
        {% if gs.settings.update_check_result.error == "http_error" %}
            {% trans "The pretalx.com server returned an error code." %}
        {% elif gs.settings.update_check_result.error == "unavailable" %}
            {% trans "The pretalx.com server could not be reached." %}
        {% elif gs.settings.update_check_result.error == "development" %}
            {% trans "This installation appears to be a development installation." %}
        {% endif %}
    </div>
    <form action="" method="post">
        {% csrf_token %}
        <p class="d-flex">
            <button type="submit" name="trigger" value="1" class="btn btn-outline-info ml-auto">
                <i class="fa fa-refresh mr-2"></i>
                {% trans "Check for updates now" %}
            </button>
        </p>
    </form>
{% else %}
    <form action="" method="post">
        {% csrf_token %}
        <p class="d-flex flex-baseline">
            {% blocktrans trimmed with date=gs.settings.update_check_last|date:"SHORT_DATETIME_FORMAT" %}
                Last updated: {{ date }}
            {% endblocktrans %}
            <button type="submit" name="trigger" value="1" class="btn btn-outline-info ml-auto">
                <i class="fa fa-refresh mr-2"></i>
                {% trans "Check for updates now" %}
            </button>
        </p>
    </form>
    <div class="table-responsive">
        <table class="table table-condensed">
            <thead>
            <tr>
                <th>{% trans "Component" %}</th>
                <th>{% trans "Installed version" %}</th>
                <th>{% trans "Latest version" %}</th>
            </tr>
            </thead>
            <tbody>
            {% for row in result_table %}
            <tr class="table-{% if row.3 %}danger{% elif row.2 == "?" %}warning{% else %}success{% endif %}">
                <td>{{ row.0 }}</td>
                <td>{{ row.1 }}</td>
                <td>{{ row.2 }}</td>
            </tr>
            {% endfor %}
            </tbody>
        </table>
    </div>
{% endif %}

<h2>{% trans "Update check settings" %}</h2>

<form action="" method="post" class="form-horizontal">
    {% csrf_token %}
    {% bootstrap_form_errors form %}
    {% bootstrap_form form layout='event' %}
    <div class="submit-group panel">
        <span></span>
        <button type="submit" class="btn btn-success btn-lg">
            <i class="fa fa-check"></i>
            {% trans "Save" %}
        </button>
    </div>
</form>

{% endblock %}
