{% load i18n %}

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

<div class="mailchimp-group-item">

    {# reset if no accordion is used #}
    {% block accordion_container_before %}
        <header class="" data-accordion-trigger>
            <h3 class="heading">
                <a data-toggle="collapse" href="#group-content-1" aria-expanded="false" aria-controls="group-content-1" class="collapsed no-icon" data-collapse-toggle>
                    {% block newsletter_heading_text %}
                        {% trans "Subscribe to Newsletter" %}
                    {% endblock newsletter_heading_text %}
                </a>
           </h3>
        </header>
        <div class="collapse" id="group-content-1">
    {% endblock accordion_container_before %}

        <div class="mailchimp-group-item-child">
             <form
                action="{% url 'mailchimp:signup_advanced' %}"
                method="post"
                class="mailchimp-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="form-group">
                        <input name="language" id="id_language" type="hidden" value="{{ request.LANGUAGE_CODE }}">
                        <input name="first_name" id="id_first_name" type="text" placeholder="{% block newsletter_first_name_text %}{% trans "First Name" %}{% endblock newsletter_first_name_text %}" class="form-control" value="{{ mailchimp_signup_form.first_name.value|default:"" }}" required>
                        <input name="last_name" id="id_last_name" type="text" placeholder="{% block newsletter_last_name_text %}{% trans "Last Name" %}{% endblock newsletter_last_name_text %}" class="form-control" value="{{ mailchimp_signup_form.last_name.value|default:"" }}" required>
                        <div class="input-group">
                            <input name="email" id="id_email" type="email" placeholder="{% block newsletter_email_field_text %}{% trans "Your Email address" %}{% endblock newsletter_email_field_text %}" class="form-control" value="{{ mailchimp_signup_form.email.value|default:"" }}" required>
                           {% block newsletter_btn_container %}
                               <span class="input-group-btn">
                                   <button type="submit" class="{% block newsletter_btn_classes_container %}btn btn-{% block newsletter_btn_variation %}primary{% endblock newsletter_btn_variation %}{% endblock newsletter_btn_classes_container %}" {% block newsletter_btn_ajax_loader %}data-btn-ajax-loader{% endblock newsletter_btn_ajax_loader %}>
                                       <span class="btn-text">
                                           {% block newsletter_btn_text %}
                                               {% trans "Send" %}
                                           {% endblock newsletter_btn_text %}
                                       </span>
                                   </button>
                               </span>
                           {% endblock newsletter_btn_container %}
                        </div>
                    </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 %}
                    <div class="alert alert-danger">
                        {{mailchimp_signup_form.email.errors}}
                    </div>
                {% endif %}

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

            </form>
         </div>

     {% block accordion_container_after %}
         </div>
     {% endblock accordion_container_after %}

</div>

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

