<?php
$headline = mb_get_block_field("component-testimonials-headline");
$text = mb_get_block_field("component-testimonials-text");
$image = mb_get_block_field("component-testimonials-image");
$buttons = mb_get_block_field("component-testimonials-buttons");
$testimonials = mb_get_block_field("component-testimonials");
//slider settings
$products_per_slide = mb_get_block_field("component-testimonials-slider-slides");
$is_infinite = mb_get_block_field("component-testimonials-slider-infinite");
$automatic_slider = mb_get_block_field("component-testimonials-slider-automatic");
$show_arrows = mb_get_block_field("component-testimonials-slider-arrows");

$id = uniqid("testimonials-slider-wrapper");

if ($testimonials) { ?>
<section <?= inoby_block_attrs($attributes, ["class" => "component-testimonials"]) ?>>
  <div class="container">
    <div class="row">
      <div class="col-6 col-sm-12">
        <?php if ($image) {
          echo mb_inoby_picture($image, "v-6", ["sm" => "v-4", "md" => "v-6", "lg" => "v-6"]);
        } ?>
      </div>
      <div class="col-6 col-sm-12">
        <?php
        if ($headline) {
          echo "<h2>" . $headline . "</h2>";
        }
        if ($text) {
          echo "<p>" . $text . "</p>";
        }
        ?>
        <div class="quote-mark mark-first"></div>
        <div <?= inoby_block_attrs($attributes, [
          "class" => "testimonials-slider",
          "id" => $id,
          "data-infinite" => $is_infinite,
          "data-slides" => $products_per_slide,
          "data-automatic" => $automatic_slider,
        ]) ?>>
          <?php foreach ($testimonials as $testimonial): ?>
          <div class="testimonial-box">
            <p>
              <?= $testimonial["testimonial-short"] ?>
              <?php 
              if(isset($testimonial["testimonial-long"])){
                echo '<a href="#0" class="show-more link">' . __("Zobraziť viac", "inoby") . "</a>";
              }
              ?>
            </p>
            <div class="author-box">
              <?php if ($testimonial["author-image"]) {
                echo '<div class="author-image">';
                echo mb_inoby_picture($testimonial["author-image"], "s-2", ["sm" => "s-2", "md" => "s-2", "lg" => "s-2"]);
                echo "</div>";
              } ?>
              <div class="author-content">
                <p class="small"><?= $testimonial["author"] ?></p>
                <span class="caption"><?= $testimonial["author-designation"] ?></span>
              </div>
            </div>
          </div>
          <?php if(isset($testimonial["testimonial-long"])){ ?>
          <div class="testimonial-popup">
            <div class="popup-content">
              <div class="close-btn">✕</div>
              <p><?= $testimonial["testimonial-long"] ?></p>
              <div class="author-box">
                <?php if ($testimonial["author-image"]) {
                  echo '<div class="author-image">';
                  echo mb_inoby_picture($testimonial["author-image"], "s-2", ["sm" => "s-2", "md" => "s-2", "lg" => "s-2"]);
                  echo "</div>";
                } ?>
                <div class="author-content">
                  <p class="small"><?= $testimonial["author"] ?></p>
                  <span class="caption"><?= $testimonial["author-designation"] ?></span>
                </div>
              </div>
            </div>
          </div>
          <?php } ?>
          <?php endforeach; ?>
        </div>
        <div class="quote-mark mark-last"></div>
        <?php if (isset($show_arrows) && $show_arrows) { ?>
        <?php get_template_part("template-parts/keen-arrows", "keen-arrows", ["slider-id" => $id]); ?>
        <?php } ?>
        <?php if ($buttons) {
          foreach ($buttons as $button) {
            echo '<a href="' . $button[1] . '" target="' . $button[2] . '" class="button ' . $button[3] . '">' . $button[0] . "</a>";
          }
        } ?>
      </div>
    </div>
  </div>
</section>
<?php }