@props([
'gallery' => null,
'alt' => '',
'mode' => 'product',
])
@php
/** @var \App\DTO\Media\OrderedGalleryDTO|null $gallery */
$mode = in_array($mode, ['product', 'service'], true) ? $mode : 'product';
$isProduct = $mode === 'product';
$items = $gallery?->items()->map(fn ($item) => $item->toArray())->values()->all() ?? [];
$first = $items[0] ?? null;
$count = count($items);
$showChrome = $isProduct || $count > 1;
@endphp
@if ($first)
$isProduct,
'site-image-gallery--service' => ! $isProduct,
])
x-data="{
active: 0,
lightbox: false,
items: @js($items),
mode: @js($mode),
select(i) { this.active = i; },
openLightbox(i) {
if (this.mode !== 'product') return;
this.active = i;
this.lightbox = true;
document.documentElement.classList.add('overflow-hidden');
},
closeLightbox() {
this.lightbox = false;
document.documentElement.classList.remove('overflow-hidden');
},
prev() { this.active = (this.active - 1 + this.items.length) % this.items.length; },
next() { this.active = (this.active + 1) % this.items.length; },
isVideo(item) { return !!(item && item.is_video); },
}"
@keydown.escape.window="lightbox && closeLightbox()"
@keydown.left.window="lightbox && items.length > 1 && prev()"
@keydown.right.window="lightbox && items.length > 1 && next()"
>
@if ($isProduct)
@else
![]()
@endif
@if ($showChrome && $count > 1)
@endif
@if ($count > 1)
! $isProduct,
])>
@endif
@if ($isProduct)
@endif
@endif