<?php

$images = mb_get_block_field("images");

$defaults = [
  "has_lightbox" => false,
];

$settings = inoby_parse_args(mb_get_block_field("settings"), $defaults, true);
$gallery_id = uniqid("grid_gallery_");
?>

<?php if (count($images)): ?>
  <div <?= inoby_block_attrs($attributes, ["id" => $gallery_id, "class" => "inoby-grid-gallery", "data-settings" => json_encode($settings)]) ?>>
    <div class="gallery">
      <?php foreach ($images as $image): ?>
          <?php if ($settings["has_lightbox"]): ?>
            <a href="<?= $image["full_url"] ?>" class="gallery-item glightbox-item" data-gallery="<?= $gallery_id ?>">
              <img src="<?= $image["full_url"] ?>" alt="gallery-img">
            </a>
          <?php else: ?>
            <div class="gallery-item">
              <img src="<?= $image["full_url"] ?>" alt="gallery-img">
            </div>
          <?php endif; ?>
      <?php endforeach; ?>
    </div>
  </div>
<?php endif; ?>
