{# Add shortcut variables that can be used in `formtag` context #}
{% set buttonsPosition = page.settings.buttonsPosition %}

{% hook 'formie.buttons.before' %}

{% set nextPage = form.getNextPage(page) %}
{% set prevPage = form.getPreviousPage(page) %}

{% formtag 'buttonWrapper' %}
    {% hook 'formie.buttons.start' %}

    {# Next button goes first. https://stackoverflow.com/a/1963285 #}

    {% formtag 'buttonContainer' %}
        {% formtag 'submitButton' %}
            {%- hook 'formie.buttons.submit-start' -%}

            {{ page.settings.submitButtonLabel | t('formie') }}

            {%- hook 'formie.buttons.submit-end' -%}
        {% endformtag %}

        {% if page.settings.showBackButton and prevPage %}
            {% formtag 'backButton' %}
                {%- hook 'formie.buttons.prev-start' -%}

                {{ page.settings.backButtonLabel | t('formie') }}

                {%- hook 'formie.buttons.prev-end' -%}
            {% endformtag %}
        {% endif %}
    {% endformtag %}

    {% formtag 'buttonContainer' %}
        {% if page.settings.showSaveButton %}
            {% formtag 'saveButton' %}
                {%- hook 'formie.buttons.draft-start' -%}

                {{ page.settings.saveButtonLabel | t('formie') }}

                {%- hook 'formie.buttons.draft-end' -%}
            {% endformtag %}
        {% endif %}
    {% endformtag %}

    {% hook 'formie.buttons.end' %}
{% endformtag %}

{% hook 'formie.buttons.after' %}