{# Add shortcut variables that can be used in `formtag` context #}
{% set currentPage = form.getCurrentPage() %}

{% formtag 'page' %}
    {% formtag 'pageContainer' %}
        {% hook 'formie.page.start' %}

        {% if form.settings.displayCurrentPageTitle %}
            {{ formtag('pageTitle', {
                text: page.label | t('formie'),
            }) }}
        {% endif %}

        {% for row in page.getRows(false) %}
            {% formtag 'row' %}
                {% for field in row.getFields(false) %}
                    {{ craft.formie.renderField(form, field, renderOptions) }}
                {% endfor %}
            {% endformtag %}
        {% endfor %}

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

    {% if submission is defined %}
        {% set flashNotice = craft.formie.plugin.service.getFlash(form.id, 'notice') %}
        {% set flashError = craft.formie.plugin.service.getFlash(form.id, 'error') %}

        {% if flashNotice and form.settings.submitActionMessagePosition == 'bottom-form' %}
            {{ formieInclude('_includes/alert-success') }}
        {% endif %}

        {% if flashError and form.settings.errorMessagePosition == 'bottom-form' %}
            {{ formieInclude('_includes/alert-error') }}
        {% endif %}
    {% endif %}

    {{ formieInclude('_includes/submit') }}
{% endformtag %}
