{% extends 'base.html' %}
{% block content %}
    {% from '_helpers.html' import render_simple_field, render_field %}

    <div class="edit-form">
        <div class="tabs collapsable">
            <ul>
                <li class="tab active" id=""><a href="{{ url_for('backups.create') }}">{{ _('Create') }}</a></li>
                <li class="tab"><a href="{{ url_for('backups.restore.restore') }}">{{ _('Restore') }}</a></li>
            </ul>
        </div>
        <div class="box-wrap inner">
            <div id="general">
                {% if backup_running %}
                    <p>
                        <span class="spinner"></span>&nbsp;<strong>{{ _('A backup is running!') }}</strong>
                    </p>
                {% endif %}

                <p>
                    {{ _('Here you can download and request a new backup, when a backup is completed you will see it listed below.') }}
                </p>
                <br>
                {% if available_backups %}
                    <ul>
                        {% for backup in available_backups %}
                            <li>
                                <a href="{{ url_for('backups.download_backup', filename=backup["filename"]) }}">{{ backup["filename"] }}</a> {{ backup["filesize"] }} {{ _('Mb') }}
                            </li>
                        {% endfor %}
                    </ul>
                {% else %}
                    <p>
                        <strong>{{ _('No backups found.') }}</strong>
                    </p>
                {% endif %}

                <a class="pure-button pure-button-primary"
                   href="{{ url_for('backups.request_backup') }}">{{ _('Create backup') }}</a>
                {% if available_backups %}
                    {# POST + CSRF token: this permanently deletes every backup archive, so it must
                       not be reachable from a bare GET (an <img src=...> on any page the operator
                       visits would have triggered it). A real form keeps it working without JS. #}
                    <form method="POST" action="{{ url_for('backups.remove_backups') }}" style="display: inline;">
                        <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                        <button type="submit" class="pure-button button-small button-error">{{ _('Remove backups') }}</button>
                    </form>
                {% endif %}

            </div>

        </div>
    </div>
{% endblock %}
