{% macro getFieldTemplate(type) -%}
    {% set fieldTemplatePath = "freeform/_templates/formatting/conversational/fields/" %}
    {{- fieldTemplatePath ~ type ~ ".twig" -}}
{%- endmacro %}

{% macro render(rows, form) %}
    {% import _self as self %}

    {% for row in rows %}

        {% set width = (12 / (row|length)) %}

        {% set questionId = loop.index %}
        {% set questionTotal = loop.length %}

        {% set attributes = form.attributes.row %}
        {% do attributes.replace('id', 'q'~questionId) %}
        {% do attributes.replace('class', 'freeform-page') %}

        {% tag attributes.tag with attributes.toHtmlTagArray %}
            <div class="freeform-question">
            {% for field in row %}

                {% do field.setParameters({
                    attributes: {
                        container: {
                            class: [
                                "freeform-col-" ~ width,
                                "freeform-fieldtype-" ~ field.type,
                            ],
                        },
                    }
                }) %}

                {% include [self.getFieldTemplate(field.type), self.getFieldTemplate("_default")] %}

            {% endfor %}
                <div class="freeform-buttons">
                    {% if questionId != questionTotal %}
                        <a href="#q{{ questionId + '1' }}">Next</a>
                    {% endif %}
                    {% if questionId == questionTotal %}
                        <button type="submit" data-button-container="submit" data-freeform-action="submit">Submit</button>
                    {% endif %}
                    {% if questionId > "1" %}
                        <a href="#q{{ questionId - '1' }}" class="previous">Previous</a>
                    {% endif %}
                </div>
            </div>
        {% endtag %}

    {% endfor %}

{% endmacro %}
