@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 = [
        [
            'text' => __('Insert first slide', 'muy-lindo'),
        ],
    ];

    // Load values and assign defaults.
    $marquee = get_field('marquee');
    $effect_type = get_field('effect_type');
    $autoplay = get_field('autoplay');
    $element_per_row = get_field('element_per_row');

    if ($effect_type == 'marquee') {
        $marquee = true;
        $className .= ' marquee';
    } else {
        $marquee = false;
    }


    $slides = get_field('slides') ?: $default_slides;
    $partners_grid = $slides;
    $grayscale = get_field('grayscale');
    $transition_speed = $marquee ? get_field('transition_speed') : 500;
    $autoplay_pause = $marquee ? 1 : get_field('autoplay_pause');
    $slides_to_view = get_field('slides_to_view');

    $boxed = get_field('boxed');

    if ($boxed) {
        $className .= ' is-boxed';
    }

@endphp

<div id="{{ esc_attr($id) }}" class="{{ esc_attr($className) }}">
    @if ($effect_type == 'marquee' || $effect_type == 'carousel')
        <div class="partners-swiper swiper" data-transition-speed="{{ $transition_speed }}"
            data-slides-to-view="{{ $slides_to_view }}" data-autoplay-pause="{{ $autoplay_pause }}">
            <!-- Additional required wrapper -->
            <div class="swiper-wrapper">
                <!-- Slides -->
                @foreach ($slides as $slide)
                    @php
                        $partner_url = isset($slide['partner_info']['url']) ? $slide['partner_info']['url'] : '';
                        $partner_title = isset($slide['partner_info']['title']) ? $slide['partner_info']['title'] : '';
                    @endphp
                    <div class="swiper-slide @if ($grayscale) grayscale @endif">
                        @if ($partner_url)
                            <a href="{{ $partner_url }}" target="_blank">
                        @endif
                        <figure>
                            @if ($slide['image'])
                                <img class="inner-slide-img" src="{!! $slide['image']['sizes']['full_hd'] !!}" alt="{{ $partner_title }}" />
                            @endif
                        </figure>
                        @if ($partner_url)
                            </a>
                        @endif
                    </div>
                @endforeach
            </div>
        </div>
    @else
        <div class="partner-grid grid grid-cols-{{ $element_per_row }} gap-8">
            @foreach ($partners_grid as $partner)
                @php
                    $partner_url = isset($partner['partner_info']['url']) ? $partner['partner_info']['url'] : '';
                    $partner_title = isset($partner['partner_info']['title']) ? $partner['partner_info']['title'] : '';
                @endphp
                @if ($partner['image'])
                    <div class="partner {{ $grayscale ? 'grayscale' : '' }}">
                        @if ($partner_url)
                            <a href="{{ $partner_url }}" target="_blank">
                        @endif
                        <figure>
                            <img src="{!! $partner['image']['sizes']['full_hd'] !!}" alt="{{ $partner_title }}" />
                        </figure>
                        @if ($partner_url)
                            </a>
                        @endif
                    </div>
                @endif
            @endforeach
        </div>
    @endif
</div>
