{{ 'section-slideshow-v2.css' | asset_url | stylesheet_tag }}

<div class='slideshow-v2'>
  <div {% render 'section-attr' %}>
    <div class='slideshow-v2__intro'>
      <div class='slideshow-v2__intro-slideshow'>
        {% for block in section.blocks %}
          <img src='{{ block.settings.image | image_url }}' width='1920' height='1080'>
        {% endfor %}
      </div>
      <div class='slideshow-v2__intro-header'>
        <div class='slideshow-v2__subtitle'>{{ section.settings.sub }}</div>
        <div class='slideshow-v2__title'>{{ section.settings.title }}</div>
      </div>
    </div>
  </div>
</div>

<script>
  const slideshowImages = document.querySelectorAll('.slideshow-v2__intro-slideshow img');
  const nextImageDelay = 5000;
  let currentImageCounter = 0;
  slideshowImages[currentImageCounter].style.opacity = 1;

  setInterval(nextImage, nextImageDelay);

  function nextImage() {
    slideshowImages[currentImageCounter].style.opacity = 0;
    currentImageCounter = (currentImageCounter + 1) % slideshowImages.length;
    slideshowImages[currentImageCounter].style.opacity = 1;
  }
</script>

{% schema %}
{
  "name": "t:sections.slideshow_v2.name",
  "tag": "section",
  "class": "section",
  "settings": [
    {
      "type": "select",
      "id": "width",
      "label": "t:sections.all.width.label",
      "default": "box",
      "options": [
        {
          "value": "box",
          "label": "t:sections.all.width.options__1.label"
        },
        {
          "value": "wide",
          "label": "t:sections.all.width.options__2.label"
        },
        {
          "value": "fullwidth",
          "label": "t:sections.all.width.options__3.label"
        }
      ]
    },
    {
      "type": "text",
      "id": "sub",
      "label": "t:sections.slideshow_v2.settings.sub.label",
      "default": "Subtitle"
    },
    {
      "type": "text",
      "id": "title",
      "label": "t:sections.slideshow_v2.settings.title.label",
      "default": "Title"
    },
    {
      "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": "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
    }
  ],
  "blocks": [
    {
      "type": "image",
      "name": "t:sections.slideshow_v2.settings.blocks.name",
      "settings": [
        {
          "type": "image_picker",
          "id": "image",
          "label": "t:sections.slideshow_v2.settings.blocks.image.label"
        }
      ]
    }
  ],
  "presets": [
    {
      "name": "t:sections.slideshow_v2.presets.name"
    }
  ]
}
{% endschema %}
