{% extends request.ajax ? 'layout_blank.html.twig' : 'layout_default.html.twig' %}

{% import 'macro_functions.html.twig' as mf %}

{% block meta_title %}{{ 'Update'|trans }}{% endblock %}

{% block content %}
    {% set update_info = admin.system_update_info %}
    <div class="card">
        <div class="card-header">
            <h1 class="card-title">{{ 'Update FOSSBilling'|trans }}</h1>
        </div>
        <div class="card-body">
            {% if admin.system_update_available or update_info['branch'] == 'preview' %}
                {% if update_info['branch'] == 'preview' %}
                    <h2 class="card-title">{{ 'Update release notes'|trans }}</h2>
                {% else %}
                    <h2 class="card-title mb-0">{{ 'Update release notes'|trans }} ({{ FOSSBillingVersion }} => {{ update_info['version'] }})</h2>
                    <span>{{ 'Required PHP version:'|trans }} {{ update_info['minimum_php_version'] }}</span>
                {% endif %}
                {% if update_info['update_type'] == 2 %}
                    <div class="alert alert-danger" role="alert">
                        <span>{{ 'This update is considered to be a major update, you should check the release notes for any breaking changes.'|trans }}</span>
                    </div>
                {% endif %}
                
                {% if update_info['update_type'] == 1 %}
                    <div class="alert alert-warning" role="alert">
                        <span>{{ 'This update is considered to be a minor update, there are low chances of incompatibilities.'|trans }}</span>
                    </div>
                {% endif %}
                    
                {{ update_info['release_notes']|markdown }}
            {% else %}
                <h2 class="card-title">{{ 'There is no update available'|trans }}</h2>
                <p>{{ 'You appear to be running the latest version of FOSSBilling, so no action is needed at the moment. If you think this is a mistake, you may use the button below to check again.'|trans }}</p>
            {% endif %}
        </div>
        <div class="card-footer">
            {% if admin.system_update_available or update_info['branch'] == 'preview' %}
                <a href="{{ 'api/admin/system/update_core'|link({ 'CSRFToken': CSRFToken }) }}"
                    class="btn btn-primary api-link"
                    data-api-reload="1"
                    data-api-confirm="Proceed with automatic update?"
                    data-api-confirm-btn="Update"
                    data-api-confirm-content="Make sure that you have made database and files backups before proceeding with automatic update. You will automatically be redirected once the update is complete.">
                    <svg class="icon">
                        <use xlink:href="#download" />
                    </svg>
                    {{ 'Update FOSSBilling'|trans }}
                </a>
            {% else %}
                <a
                    class="btn btn-primary disabled"
                    aria-disabled="true">
                    <svg class="icon">
                        <use xlink:href="#download" />
                    </svg>
                    {{ 'Update FOSSBilling'|trans }}
                </a>
            {% endif %}
            <a href="{{ 'api/admin/system/recheck_update'|link({ 'CSRFToken': CSRFToken }) }}"
                class="btn btn-primary api-link"
                data-api-reload="1">
                <svg class="icon">
                    <use xlink:href="#refresh" />
                </svg>
                {{ 'Check for Updates'|trans }}
            </a>
            <a href="{{ 'api/admin/system/manual_update'|link({ 'CSRFToken': CSRFToken }) }}" class="btn btn-primary api-link" data-api-confirm="If you run into any issues, you can revert to the old config which will be saved as config.old.php." data-api-msg="Patches applied and configuration updated.">
                <svg class="icon">
                    <use xlink:href="#cog-play" />
                </svg>
                {{ 'Apply Patches & Update Configuration'|trans }}
            </a>
            <br />
            <span class="text-muted">{{ "Applying patches and updating the configuration should be performed automatically, you don't need to use that button unless you are experiencing issues."|trans }}<br />
            <span class="text-muted">{{ 'Last update check:'|trans }} {{ update_info['last_check']|format_datetime() }}.</span><br />
            <span class="text-muted"> {{ 'Next update check:'|trans }} {{ update_info['next_check']|format_datetime() }}.</span>
        </div>
    </div>
{% endblock %}
