{% comment %}
  Renders a popup-newsletter-v2

  Accepts:
  - sub_heading: {String} Subheading of the popup-newsletter (Optional)
  - description: {String} Description of the popup-newsletter (Optional)
  - placeholder: {String} Placeholder for the input signup form (Optional)
  - button_label: {String} Label for the button
  - img_src: {String} Image for the popup-newsletter

  Usage:
  {% render 'popup-newsletter-v2',
    sub_heading: 'Get 20% discount shipped to your inbox',
    description: 'Subscribe to our newsletter and we will ship <strong>20% discount code</strong> today',
    placeholder: 'Enter Your Email ...',
    button_label: 'Subscribe',
    img_src: '{{img_src}}'
   %}
{% endcomment %}

{% assign sub_heading = sub_heading | default: settings.popup_newsletter_sub_heading %}
{% assign desc_popup = desc_popup | default: settings.popup_newsletter_desc %}
{% assign placeholder = placeholder | default: settings.popup_newsletter_place_holder %}
{% assign button_label = button_label | default: settings.popup_newsletter_btn_label %}
{% assign img_src = img_src | default: settings.popup_newsletter_image %}

{% assign icon_1 = icon_1 | default: settings.popup_newsletter_icon_1 %}
{% assign icon_2 = icon_2 | default: settings.popup_newsletter_icon_2 %}
{% assign icon_3 = icon_3 | default: settings.popup_newsletter_icon_3 %}
{% assign icon_4 = icon_4 | default: settings.popup_newsletter_icon_4 %}

{%- assign icon_1_label = icon_1_label | default: settings.popup_newsletter_icon_1_label %}
{%- assign icon_2_label = icon_2_label | default: settings.popup_newsletter_icon_2_label %}
{%- assign icon_3_label = icon_3_label | default: settings.popup_newsletter_icon_3_label %}
{%- assign icon_4_label = icon_4_label | default: settings.popup_newsletter_icon_4_label %}

{% assign url_social_media_1 = url_social_media_1 | default: settings.popup_newsletter_url_social_media_1 %}
{% assign url_social_media_2 = url_social_media_2 | default: settings.popup_newsletter_url_social_media_2 %}
{% assign url_social_media_3 = url_social_media_3 | default: settings.popup_newsletter_url_social_media_3 %}
{% assign url_social_media_4 = url_social_media_4 | default: settings.popup_newsletter_url_social_media_4 %}

<div class='popup-newsletter-v2'>
  <xo-grid style='--xo-grid-col-gap: 0;'>
    <div class='popup-newsletter-v2__left' style='--xs: 12; --sm: 12; --lg: 5;'>
      <div class='popup-newsletter-v2__img'>
        {% render 'image', image: {{img_src}} %}
      </div>
    </div>
    <div class='popup-newsletter-v2-right' style='--xs: 12; --sm: 12; --lg: 7;'>
      <div class='popup-newsletter-v2__close'>
        <xo-modal-trigger class='xo-modal-content-style1__close{% if close_class %} {{ close_class }}{% endif %}'>
          {% render 'icon', name: 'close2', icon_size: '15' %}
        </xo-modal-trigger>
      </div>
      <div class='popup-newsletter-v2__content'>
        {%- if sub_heading != blank -%}
          <h1 class='popup-newsletter-v2__sub'>{{ sub_heading }}</h1>
        {%- endif -%}
        {%- if desc_popup != blank -%}
          <div class='popup-newsletter-v2__desc'>
            {{ desc_popup }}
          </div>
        {%- endif -%}

        <div class='popup-newsletter-v2__signup'>
          {%- form 'customer', id: 'ContactFooter' -%}
            <input type='hidden' name='contact[tags]' value='newsletter'>
            <div class='popup-newsletter-v2__form'>
              {% assign value = form.email %}
              {% capture attr %}
                  aria-required='true'
                  autocorrect='off'
                  {% if form.errors %}
                  autofocus
                  aria-invalid='true'
                  aria-describedby='ContactFooter-error'
                  {% elsif form.posted_successfully? %}
                  aria-describedby='ContactFooter-success'
                  {% endif %}
                  required
                {% endcapture -%}
              {% render 'field-input', type: 'email', name: 'contact[email]', value: value, placeholder: 'Enter your email...', attr: attr %}
              {% render 'button', type: 'submit', text: {{button_label}}, style: 'secondary', size: 'md', radius: 0, padding: 3, background_color: '#bc9e6b', text_color: '#fff' %}
            </div>
            {%- if form.errors -%}
              <small id='ContactFooter-error' class='newsletter-form__message newsletter-form__message--error'>
                {%- render 'icon', name: 'error' -%}
                {{- form.errors.translated_fields.email | capitalize }}
                {{ form.errors.messages.email -}}
              </small>
            {%- endif -%}
            {%- if form.posted_successfully? -%}
              <div
                class='newsletter-form__message newsletter-form__message--success'
                id='ContactFooter-success'
                tabindex='-1'
                autofocus
              >
                {% render 'icon', name: 'success' -%}
                {{- 'newsletter.success' | t }}
              </div>
            {%- endif -%}
          {%- endform -%}
        </div>

        <div class='popup-newsletter-v2-social'>
          <ul class='popup-newsletter-v2-social__list'>
            <xo-tooltip xo-title='{{icon_1_label}}'>
              <a href='{{url_social_media_1}}' class='popup-newsletter-v2-social__link'>
                {{ icon_1 }}
              </a>
            </xo-tooltip>

            <xo-tooltip xo-title='{{icon_2_label}}'>
              <a href='{{url_social_media_2}}' class='popup-newsletter-v2-social__link'>
                {{ icon_2 }}
              </a>
            </xo-tooltip>

            <xo-tooltip xo-title='{{icon_3_label}}'>
              <a href='{{url_social_media_3}}' class='popup-newsletter-v2-social__link'>
                {{ icon_3 }}
              </a>
            </xo-tooltip>

            <xo-tooltip xo-title='{{icon_4_label}}'>
              <a href='{{url_social_media_4}}' class='popup-newsletter-v2-social__link'>
                {{ icon_4 }}
              </a>
            </xo-tooltip>
          </ul>
        </div>
      </div>
    </div>
  </xo-grid>
</div>
