<?php
$carousel_boxes = mb_get_block_field("carousel-boxes");
$num_of_slides = count($carousel_boxes);
$per_slide_lg = mb_get_block_field("per_slide_lg") ?? 4;
$per_slide_md = mb_get_block_field("per_slide_md") ?? 2.33;
$per_slide_sm = mb_get_block_field("per_slide_sm") ?? 1.33;
$spacing = mb_get_block_field("spacing") ?? 0;

$id = uniqid("carousel-boxes-wrapper");
if ($carousel_boxes) { ?>
  <section <?= inoby_block_attrs($attributes, ["class" => "carousel-boxes"]) ?>>
    <div class="container" style="padding-right: 0;">
      <div class="row">
        <div class="col-12">
          <div <?= inoby_block_attrs($attributes, [
                  "class" => "inoby-carousel-boxes fluid-right-full",
                  "id" => $id,
                  "data-infinite" => $infinite,
                  "data-slides-lg" => $per_slide_lg,
                  "data-slides-md" => $per_slide_md,
                  "data-slides-sm" => $per_slide_sm,
                  "data-numslides" => $num_of_slides,
                  "data-spacing" => $spacing,
                ]) ?>>
            <?php
            echo '<div class="carousel-boxes-wrap">';

            foreach ($carousel_boxes as $box) {
              $box_url = $box["url"] ?? "";
              if (isset($box["bg"])) {
                echo '<div class="carousel-box" style="background: center/cover no-repeat url(' . wp_get_attachment_image_src(reset($box["bg"]), "o-6")[0] . ');">';
              } else {
                echo '<div class="carousel-box carousel-box-placeholder">';
              }
              echo isset($box["headline"]) ? "<h6>" . $box["headline"] . "</h6>" : "";
              echo isset($box["text"]) ? "<p>" . $box["text"] . "</p>" : "";
              if ($box_url) {
                echo '<a class="link" href="' . $box_url . '">' . __("Zisti viac", "inoby") . "</a>";
              }
              echo "</div>";
            }
            echo "</div>";
            ?>
          </div>
        </div>
      </div>
    </div>
  </section>
<?php }
