<?php $collection = cms_collection($module['collection'] ?? 'reviews'); ?>
<section class="section section--muted" id="<?= e($module['anchor'] ?? 'reviews') ?>">
  <div class="container">
    <div class="section-heading">
      <div class="eyebrow"><?= e($module['eyebrow'] ?? '') ?></div>
      <h2><?= e($module['title'] ?? '') ?></h2>
      <p><?= e($module['text'] ?? 'Настоящие впечатления гостей о домиках, животных и самом отдыхе.') ?></p>
    </div>
    <div class="reviews-grid">
      <?php foreach (($collection['items'] ?? []) as $item): ?>
        <?php $photos = array_values(array_filter($item['photos'] ?? [])); ?>
        <article class="card review-card review-card--rich">
          <div class="review-card__top">
            <div class="review-card__avatar">
              <?php if (!empty($item['photo'])): ?>
                <button type="button" data-open-lightbox="<?= e($item['photo']) ?>" style="padding:0;border:0;background:transparent;display:block;width:100%;height:100%;cursor:zoom-in">
                  <img src="<?= e($item['photo']) ?>" alt="<?= e($item['name'] ?? 'Гость') ?>" loading="lazy">
                </button>
              <?php else: ?>
                <span><?= e(mb_substr((string)($item['name'] ?? 'Г'), 0, 1)) ?></span>
              <?php endif; ?>
            </div>
            <div>
              <div class="review-card__name"><?= e($item['name'] ?? '') ?></div>
              <?php if (!empty($item['location']) || !empty($item['date'])): ?>
                <div class="review-card__meta"><?= e(trim(($item['location'] ?? '') . (!empty($item['location']) && !empty($item['date']) ? ' • ' : '') . ($item['date'] ?? ''))) ?></div>
              <?php endif; ?>
            </div>
            <div class="review-card__rating" aria-label="Рейтинг <?= (int)($item['rating'] ?? 5) ?> из 5"><?= str_repeat('★', max(1, min(5, (int)($item['rating'] ?? 5)))) ?></div>
          </div>
          <p><?= e($item['text'] ?? '') ?></p>
          <?php if ($photos): ?>
            <div class="review-card__photos">
              <?php foreach ($photos as $photo): ?>
                <button type="button" data-open-lightbox="<?= e($photo) ?>" aria-label="Открыть фото отзыва">
                  <img src="<?= e($photo) ?>" alt="<?= e($item['name'] ?? 'Фото гостя') ?>" loading="lazy">
                </button>
              <?php endforeach; ?>
            </div>
          <?php endif; ?>
        </article>
      <?php endforeach; ?>
    </div>
  </div>
</section>
