@php
  /*
  * Nei template dei blocchi creati con ACF non sarà possibile usare blade
  * perchè non viene interpretato nella preview in admin
  */

  // Create id attribute allowing for custom "anchor" value.
  $id = 'muy-partners-' . $block['id'];
  if( !empty($block['anchor']) ) {
    $id = $block['anchor'];
  }

  // Create class attribute allowing for custom "className" and "align" values.
  $className = 'muy-'.$block['slug'];
  if( !empty($block['className']) ) {
    $className .= ' ' . $block['className'];
  }
  if( !empty($block['align']) ) {
    $className .= ' align' . $block['align'];
  }

  $default_slides = array(
    array(
      'text'  => __('Insert first slide', 'muy-lindo'),
    ),
  );

  // Load values and assign defaults.
  $slides = get_field('slides') ?: $default_slides;
  $grayscale = get_field('grayscale');
  $autoplay_speed = get_field('autoplay_speed');
  $slides_to_view = get_field('slides_to_view');
  $boxed = get_field('boxed');
  $autoplay = get_field('autoplay');

@endphp

<div id="{{ esc_attr($id) }}" class="{{ esc_attr($className) }} @if($boxed) is-boxed @endif">
<div class="partners-swiper" data-autoplay-speed="{{$autoplay_speed}}"
  data-slides-to-view="{{$slides_to_view}}"
  data-autoplay="{{$autoplay}}">
      <!-- Additional required wrapper -->
      <div class="swiper-wrapper">
        <!-- Slides -->
        @foreach ($slides as $slide)
        @php
            $partner_url = isset($slide['partner_info']['url']);
            $partner_title = isset($slide['partner_info']['title']);
        @endphp
        <div class="swiper-slide @if($grayscale) grayscale @endif">
          @if ($partner_url)
            <a href="{{$slide['partner_info']['url']}}" target="_blank">
          @endif
            <figure>
                @if ($slide['image'])
                  <img class="inner-slide-img" src="{!! $slide['image']['sizes']['full_hd'] !!}"
                  alt="{{$partner_title ? $slide['partner_info']['title'] : ''}}"/>
                @endif
            </figure>
          @if ($partner_url)
            </a>
          @endif
        </div>
        @endforeach
    </div>
</div>
