<?php
$collection = cms_collection('gallery');
$images = !empty($collection['items']) ? $collection['items'] : ($module['images'] ?? []);
$animalsPopup = cms_animals_popup_settings($settings);
$animalsButtonLabel = (string) ($animalsPopup['button_label'] ?? 'Про наших животных');
?>
<section class="section" id="<?= e($module['anchor'] ?? '') ?>">
  <div class="container">
    <div class="section-heading">
      <div class="eyebrow"><?= e($module['eyebrow'] ?? '') ?></div>
      <h2><?= e($module['title'] ?? '') ?></h2>
      <?php if (!empty($module['text'])): ?><p><?= e($module['text']) ?></p><?php endif; ?>
    </div>
    <div class="gallery-carousel" data-gallery-carousel>
      <button class="gallery-carousel__nav gallery-carousel__nav--prev" type="button" data-gallery-prev aria-label="Предыдущее фото">‹</button>
      <div class="gallery-track" data-gallery-track>
        <?php foreach ($images as $image): ?>
          <figure class="gallery-card gallery-card--compact">
            <button type="button" class="gallery__zoom" data-open-lightbox="<?= e($image['src'] ?? '') ?>">
              <img src="<?= e($image['src'] ?? '') ?>" alt="<?= e($image['alt'] ?? '') ?>" loading="lazy">
            </button>
            <?php if (!empty($image['caption'])): ?><figcaption><?= e($image['caption']) ?></figcaption><?php endif; ?>
          </figure>
        <?php endforeach; ?>
      </div>
      <button class="gallery-carousel__nav gallery-carousel__nav--next" type="button" data-gallery-next aria-label="Следующее фото">›</button>
    </div>
  </div>

  <div class="container">
    <div class="gallery-extra-actions">
      <button class="button button--ghost button--animals" type="button" data-open-animals-popup onclick="window.SiteOpenAnimalsInfo && window.SiteOpenAnimalsInfo(); return false;"><?= e($animalsButtonLabel) ?></button>
    </div>
  </div>
</section>
