{{ 'section-newsletter-v4.css' | asset_url | stylesheet_tag }}

<section {% render 'section-attr', style: 'border-top: solid 0.1rem rgba(var(--color-border),0.1); --pt-mobile: 50px; --pb-mobile: 50px' %}>
  {% render 'section-bg-image' %}

  <xo-container>
    <div class='newsletter-v4'>
      <div class='newsletter-v4__all'>
        <div class='newsletter-v4__info'>
          <h3 class='newsletter-v4__title'>
            {{ section.settings.title }}
          </h3>
          <div class='newsletter-v4__title-sub'>
            {{ section.settings.title_sub }}
          </div>
        </div>
        <div class='newsletter-v4__form'>
          {%- form 'customer', id: 'ContactFooter', class: 'xo-footer-block__form' -%}
            <input type='hidden' name='contact[tags]' value='newsletter'>
            <div class='newsletter-v4__input-btn'>
              {% assign value = form.email %}
              {% assign label = 'newsletter.label' | t %}
              {% 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: 'Your email address...', attr: attr %}

              {% comment %} <div class='newsletter-v4__btn'>
                {% render 'button',
                  text: section.settings.button_text,
                  link: section.settings.button_link,
                  mode: section.settings.button_mode,
                  style: section.settings.button_style,
                  size: section.settings.button_size,
                  radius: section.settings.button_radius,
                  padding: section.settings.button_padding,
                  class: 'email-v02',
                  type: 'submit'
                %}
              </div> {% endcomment %}
            </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>
    </div>
  </xo-container>
</section>

<script>
  document.addEventListener('DOMContentLoaded', function () {
    const newsletterTitle = document.querySelector('.newsletter-v4__title');
    if (newsletterTitle) {
      const originalText = newsletterTitle.innerHTML;
      const highlightedText = originalText.replace(/NEWSLETTER/gi, '<span class="newsletter-v4__highlight">NEWSLETTER</span>');
      newsletterTitle.innerHTML = highlightedText;
    }
  });
</script>

{% schema %}
{
  "name": "t:sections.newsletter_v4.name",
  "tag": "section",
  "class": "section",
  "settings": [
    {
      "type": "text",
      "id": "title",
      "label": "t:sections.newsletter_v4.settings.title.label"
    },
    {
      "type": "text",
      "id": "title_sub",
      "label": "t:sections.newsletter_v4.settings.title-sub.label"
    },
    {
      "type": "header",
      "content": "t:sections.all.button_heading.content"
    },
    {
      "type": "text",
      "id": "button_text",
      "label": "t:sections.all.button_text.label",
      "default": "ALL PRODUCTS"
    },
    {
      "type": "url",
      "id": "button_link",
      "label": "t:sections.all.button_link.label",
      "default": "/collections/all"
    },
    {
      "type": "select",
      "id": "button_mode",
      "label": "t:sections.all.button_mode.label",
      "options": [
        {
          "value": "light",
          "label": "t:sections.all.button_mode.option__1.label"
        },
        {
          "value": "dark",
          "label": "t:sections.all.button_mode.option__2.label"
        },
        {
          "value": "accent",
          "label": "t:sections.all.button_mode.option__3.label"
        }
      ],
      "default": "light"
    },
    {
      "type": "select",
      "id": "button_style",
      "label": "t:sections.all.button_style.label",
      "options": [
        {
          "value": "primary",
          "label": "t:sections.all.button_style.option__1.label"
        },
        {
          "value": "secondary",
          "label": "t:sections.all.button_style.option__2.label"
        },
        {
          "value": "tertiary",
          "label": "t:sections.all.button_style.option__3.label"
        },
        {
          "value": "link",
          "label": "t:sections.all.button_style.option__4.label"
        }
      ],
      "default": "secondary"
    },
    {
      "type": "select",
      "id": "button_size",
      "label": "t:sections.all.button_size.label",
      "options": [
        {
          "value": "xs",
          "label": "t:sections.all.button_size.option__0.label"
        },
        {
          "value": "sm",
          "label": "t:sections.all.button_size.option__1.label"
        },
        {
          "value": "md",
          "label": "t:sections.all.button_size.option__2.label"
        },
        {
          "value": "lg",
          "label": "t:sections.all.button_size.option__3.label"
        }
      ],
      "default": "sm"
    },
    {
      "type": "range",
      "id": "button_radius",
      "label": "t:sections.all.button_radius.label",
      "max": 4,
      "min": 0,
      "step": 0.2,
      "unit": "rem",
      "default": 0.8
    },
    {
      "type": "range",
      "id": "button_padding",
      "label": "t:sections.all.button_padding.label",
      "info": "t:sections.all.button_padding.info",
      "max": 10,
      "min": 0,
      "step": 0.2,
      "unit": "rem",
      "default": 1.4
    },
    {
      "type": "header",
      "content": "t:sections.all.heading.content"
    },
    {
      "type": "color_scheme",
      "id": "color_scheme",
      "label": "t:sections.all.color_scheme.label"
    },
    {
      "type": "color",
      "id": "background_color",
      "label": "t:sections.all.bg_color.label"
    },
    {
      "type": "color_background",
      "id": "background_gradient",
      "label": "t:sections.all.bg_gradient.label"
    },
    {
      "type": "image_picker",
      "id": "background_image_desktop",
      "label": "t:sections.all.background_image_desktop.label"
    },
    {
      "type": "image_picker",
      "id": "background_image_mobile",
      "label": "t:sections.all.background_image_mobile.label"
    },
    {
      "type": "checkbox",
      "id": "use_parallax",
      "label": "t:sections.all.use_parallax.label",
      "default": true
    },
    {
      "type": "number",
      "id": "padding_top",
      "label": "t:sections.all.padding_top.label",
      "default": 50
    },
    {
      "type": "number",
      "id": "padding_bottom",
      "label": "t:sections.all.padding_bottom.label",
      "default": 50
    }
  ],
  "presets": [
    {
      "name": "t:sections.newsletter_v4.presets.name"
    }
  ]
}
{% endschema %}
