{% load i18n %}

{# utility block #}
{% block newsletter_form_before %}
{% endblock newsletter_form_before %}

<form
    action="{% url 'mailchimp:signup' %}"
    method="post"
    class="signup-form ajax-form validate-form {% block newsletter_form_additional_classes %}{% endblock newsletter_form_additional_classes %}"
    role="form"
    id="{% block newsletter_form_id %}mailchimp-signup-form{% endblock newsletter_form_id %}"
    data-success-data-layer-event="{% block newsletter_success_data_layer_event %}newsletter.sent{% endblock newsletter_success_data_layer_event %}"
    {% block newsletter_form_additional_attributes %}{% endblock newsletter_form_additional_attributes %}
    >

    {# utility block #}
    {% block newsletter_form_group_before %}
    {% endblock newsletter_form_group_before %}

    {% block newsletter_input_group_container %}
        <div class="signup-form__form-container {% block newsletter_form_group_class %}input-group{% endblock newsletter_form_group_class %}">
            <input name="language" id="id_language" type="hidden" value="{{ request.LANGUAGE_CODE }}">
            <input name="email" id="id_email" type="email" placeholder="{% block newsletter_email_text %}{% trans "Your Email address" %}{% endblock newsletter_email_text %}" class="signup-form__input form-control" value="{{ mailchimp_signup_form.email.value|default:"" }}" required>
            {% block newsletter_btn_container %}
                <span class="signup-form__input-group-btn input-group-btn">
                    <button type="submit" class="signup-form__btn {% block newsletter_btn_classes_container %}{% endblock newsletter_btn_classes_container %}" {% block newsletter_btn_ajax_loader %}{% endblock newsletter_btn_ajax_loader %}>
                        <span class="signup-form__btn-text btn-text">
                            {% block newsletter_btn_text %}
                                {% trans "Send" %}
                            {% endblock newsletter_btn_text %}
                        </span>
                    </button>
                </span>
            {% endblock newsletter_btn_container %}
        </div>
    {% endblock newsletter_input_group_container %}

    {# utility block #}
    {% block newsletter_form_group_after %}
    {% endblock newsletter_form_group_after %}

    {# something wrong with the email format #}
    {% if mailchimp_signup_form.email.errors %}
        {% block newsletter_email_error_container %}
            <div class="alert alert-danger">
                {{mailchimp_signup_form.email.errors}}
            </div>
        {% endblock newsletter_email_error_container %}
    {% endif %}

    {# any other error messages #}
    {% if mailchimp_signup_form.non_field_errors %}
        {% block newsletter_field_error_container %}
            {% for error in mailchimp_signup_form.non_field_errors %}
                <div class="alert alert-danger">
                    {{ error|escape }}
                </div>
            {% endfor %}
        {% endblock newsletter_field_error_container %}
    {% endif %}

</form>

{# utility block #}
{% block newsletter_form_after %}
{% endblock newsletter_form_after %}
