{% hook 'formie.field.field-before' %}

{% set value = value ?? renderOptions.value ?? element.getFieldValue(field.fieldKey) ?? field.normalizeValue(field.getDefaultValue(), null) %}
{% set errors = element ? element.getErrors(field.fieldKey) : [] %}

{% set labelPosition = craft.formie.getLabelPosition(field, form) %}
{% set subFieldLabelPosition = craft.formie.getLabelPosition(field, form, true) %}
{% set instructionsPosition = craft.formie.getInstructionsPosition(field, form) %}

{% fieldtag 'field' %}
    {% hook 'formie.field.field-start' %}

    {% fieldtag 'fieldContainer' %}
        {% hook 'formie.field.input-before' %}

        {{ formieInclude('_includes/label', { position: 'above' }) }}
        {{ formieInclude('_includes/instructions', { position: 'above' }) }}

        {% fieldtag 'fieldInputWrapper' %}
            {% hook 'formie.field.input-start' %}

            {{ field.getFrontEndInputHtml(form, value, renderOptions | merge({
                submission: element,
                errors: errors,
            })) }}

            {% hook 'formie.field.input-end' %}
        {% endfieldtag %}

        {{ formieInclude('_includes/label', { position: 'below' }) }}
        {{ formieInclude('_includes/instructions', { position: 'below' }) }}

        {% hook 'formie.field.input-after' %}
    {% endfieldtag %}

    {% if errors %}
        {{ formieInclude('_includes/field-errors') }}
    {% endif %}

    {% hook 'formie.field.field-end' %}
{% endfieldtag %}

{% hook 'formie.field.field-after' %}
