{#
/**
 * @file
 * Theme override for product images field with carousel functionality.
 *
 * This template is used when the carousel setting is enabled in theme settings.
 * It provides a carousel interface with thumbnail navigation and arrows.
 *
 * Available variables:
 * - attributes: HTML attributes for the containing element.
 * - label_hidden: Whether to show the field label or not.
 * - title_attributes: HTML attributes for the title.
 * - label: The label for the field.
 * - multiple: TRUE if a field can contain multiple items.
 * - items: List of all the field items. Each item contains:
 *   - attributes: List of HTML attributes for each item.
 *   - content: The field item's content.
 * - entity_type: The entity type to which the field belongs.
 * - field_name: The name of the field.
 * - field_type: The type of the field.
 * - label_display: The display settings for the label.
 *
 * @see template_preprocess_field()
 */
#}
{{ attach_library('belgrade/product.images.carousel') }}
{%
  set classes = [
    'field',
    'field--name-' ~ field_name|clean_class,
    'field--type-' ~ field_type|clean_class,
    'field--label-' ~ label_display,
    label_display == 'inline' ? 'clearfix',
    'product-images',
    'product-images--carousel',
  ]
%}
{%
  set title_classes = [
    'field__label',
    'fw-bold',
    label_display == 'visually_hidden' ? 'visually-hidden',
  ]
%}

{% if label_hidden %}
  {% if multiple %}
    <div{{ attributes.addClass(classes, 'field__items') }}>
      <div class="f-carousel product-carousel" id="product-carousel-{{ random() }}">
        {% for item in items %}
          <div class="f-carousel__slide" data-thumb-src="{{ file_url(item.content['#item'].entity.fileuri) }}">
            {% if carousel_functionality == 'panzoom' %}
              <img class="f-panzoom__content" data-lazy-src="{{ file_url(item.content['#item'].entity.fileuri) }}" src="{{ file_url(item.content['#item'].entity.fileuri) }}" alt="{{ item.content['#item'].alt }}" width="{{ item.content['#item'].width }}" height="{{ item.content['#item'].height }}" />
            {% elseif carousel_functionality == 'fancybox' %}
              <a href="{{ file_url(item.content['#item'].entity.fileuri) }}" data-fancybox="product-gallery">
                {{ item.content }}
              </a>
            {% else %}
              {{ item.content }}
            {% endif %}
          </div>
        {% endfor %}
      </div>
    </div>
  {% else %}
    {% for item in items %}
    <div{{ attributes.addClass(classes, 'field__item') }}>
      <div class="f-carousel__slide">
        {% if carousel_functionality == 'panzoom' %}
          <img class="f-panzoom__content" data-lazy-src="{{ file_url(item.content['#item'].entity.fileuri) }}" src="{{ file_url(item.content['#item'].entity.fileuri) }}" alt="{{ item.content['#item'].alt }}" width="{{ item.content['#item'].width }}" height="{{ item.content['#item'].height }}" />
        {% elseif carousel_functionality == 'fancybox' %}
          <a href="{{ file_url(item.content['#item'].entity.fileuri) }}" data-fancybox="product-gallery">
            {{ item.content }}
          </a>
        {% else %}
          {{ item.content }}
        {% endif %}
      </div>
    </div>
    {% endfor %}
  {% endif %}
{% else %}
  <div{{ attributes.addClass(classes) }}>
    <div{{ title_attributes.addClass(title_classes) }}>{{ label }}</div>
    {% if multiple %}
      <div class="field__items">
        <div class="f-carousel product-carousel" id="product-carousel-{{ random() }}">
          {% for item in items %}
            <div class="f-carousel__slide" data-thumb-src="{{ file_url(item.content['#item'].entity.fileuri) }}">
              {% if carousel_functionality == 'panzoom' %}
                <img class="f-panzoom__content" data-lazy-src="{{ file_url(item.content['#item'].entity.fileuri) }}" src="{{ file_url(item.content['#item'].entity.fileuri) }}" alt="{{ item.content['#item'].alt }}" width="{{ item.content['#item'].width }}" height="{{ item.content['#item'].height }}" />
              {% elseif carousel_functionality == 'fancybox' %}
                <a href="{{ file_url(item.content['#item'].entity.fileuri) }}" data-fancybox="product-gallery">
                  {{ item.content }}
                </a>
              {% else %}
                {{ item.content }}
              {% endif %}
            </div>
          {% endfor %}
        </div>
      </div>
    {% else %}
      {% for item in items %}
        <div class="field__item">
          <div class="f-carousel__slide">
            {% if carousel_functionality == 'panzoom' %}
              <img class="f-panzoom__content" data-lazy-src="{{ file_url(item.content['#item'].entity.fileuri) }}" src="{{ file_url(item.content['#item'].entity.fileuri) }}" alt="{{ item.content['#item'].alt }}" width="{{ item.content['#item'].width }}" height="{{ item.content['#item'].height }}" />
            {% elseif carousel_functionality == 'fancybox' %}
              <a href="{{ file_url(item.content['#item'].entity.fileuri) }}" data-fancybox="product-gallery">
                {{ item.content }}
              </a>
            {% else %}
              {{ item.content }}
            {% endif %}
          </div>
        </div>
      {% endfor %}
    {% endif %}
  </div>
{% endif %}
