<?php
$products_per_slide = mb_get_block_field("products-per-slide");
$is_infinite = mb_get_block_field("is-infinite");
$automatic_slider = mb_get_block_field("automatic-slider");
$show_arrows = mb_get_block_field("show-arrows");
$post_ids = mb_get_block_field("custom_posts");

// odlozim si pointer na aktualy post lebo ho budem v loope menit
$current_post = &$GLOBALS["post"] ?? null;
$id = uniqid("product-slider-wrapper");

if ($post_ids): ?>
<section <?= inoby_block_attrs($attributes, ["class" => "component-product-slider"]) ?>>
  <div class="container">
    <div class="row">
      <div class="col-12">
        <div <?= inoby_block_attrs($attributes, [
          "class" => "inoby-product-slider",
          "id" => $id,
          "data-infinite" => $is_infinite,
          "data-slides" => $products_per_slide,
          "data-automatic" => $automatic_slider,
        ]) ?>>
          <div class="gallery product-slider">
            <?php
            woocommerce_product_loop_start();
            foreach ($post_ids as $product_id):
              setup_postdata($GLOBALS["post"] = &$product_id);
              wc_get_template_part("content", "product");
            endforeach;
            // vratim tam povodny post
            setup_postdata($GLOBALS["post"] = &$current_post);
            woocommerce_product_loop_end();
            ?>
            <?php if (isset($show_arrows) && $show_arrows) { ?>
            <?php get_template_part("template-parts/keen-arrows", "keen-arrows", ["slider-id" => $id]); ?>
            <?php } ?>
          </div>
        </div>
      </div>
    </div>
  </div>
</section>
<?php endif;
