{# Galerie : image principale + images, dédoublonnées ; mosaïque desktop / carrousel scroll-snap mobile + modale Bootstrap #}
{% set gallery = [] %}
{% set gallery_urls = [] %}
{% if hotel_data.thumbImage is defined and hotel_data.thumbImage is not empty %}
{% set gallery = gallery|merge([{url: hotel_data.thumbImage, alt: hotel_data.name}]) %}
{% set gallery_urls = gallery_urls|merge([hotel_data.thumbImage]) %}
{% endif %}
{% for image in hotel_data.images|default([]) %}
{% if image.url is not empty and image.url not in gallery_urls %}
{% set gallery = gallery|merge([{url: image.url, alt: image.alt ?: hotel_data.name}]) %}
{% set gallery_urls = gallery_urls|merge([image.url]) %}
{% endif %}
{% endfor %}
{% if gallery is empty %}
{% set gallery = [{url: asset('uploads/image_not_available.webp'), alt: hotel_data.name}] %}
{% endif %}
{% set gallery_count = gallery|length %}
<div class="hd-gallery">
<div class="hd-pics hd-pics--{{ min(gallery_count, 3) }}" data-hotel-detail-target="gallery"
data-action="scroll->hotel-detail#updateCounter">
{% for image in gallery %}
<button type="button" class="hd-pic {{ loop.first ? 'hd-pic--main' : '' }} {{ loop.index > 3 ? 'hd-pic--extra' : '' }}"
data-action="hotel-detail#openGallery" data-index="{{ loop.index0 }}"
aria-label="{{ image.alt }} ({{ loop.index }}/{{ gallery_count }})">
<img src="{{ image.url }}" alt="{{ image.alt }}"
{{ loop.first ? 'fetchpriority="high"' : 'loading="lazy"' }}
onerror="this.onerror=null;this.src='{{ asset('uploads/image_not_available.webp') }}';">
</button>
{% endfor %}
</div>
{% if gallery_count > 1 %}
<span class="hd-pics-counter" data-hotel-detail-target="counter">1 / {{ gallery_count }}</span>
{% endif %}
<button type="button" class="hd-pics-all" data-action="hotel-detail#openGallery" data-index="0">
<i class="bi bi-images" aria-hidden="true"></i>
{{ 'Pages.HotelDetail.SeeAllPhotos'|trans({'%count%': gallery_count}, 'messages_front') }}
</button>
</div>
<div class="modal fade hd-gallery-modal" id="hdGalleryModal" tabindex="-1" aria-hidden="true"
data-hotel-detail-target="galleryModal">
<div class="modal-dialog modal-xl modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">{{ hotel_data.name }}</h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div id="hdGalleryCarousel" class="carousel slide" data-bs-ride="false" data-bs-interval="false"
data-hotel-detail-target="carousel">
<div class="carousel-inner">
{% for image in gallery %}
<div class="carousel-item {{ loop.first ? 'active' : '' }}">
<img src="{{ image.url }}" alt="{{ image.alt }}" loading="lazy">
<div class="hd-carousel-caption">{{ loop.index }} / {{ gallery_count }}</div>
</div>
{% endfor %}
</div>
{% if gallery_count > 1 %}
<button class="carousel-control-prev" type="button" data-bs-target="#hdGalleryCarousel" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#hdGalleryCarousel" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
</button>
{% endif %}
</div>
</div>
</div>
</div>
</div>