<?php 
/* 
* Block Name: Slider
* Post Type: page, post
*/
?>
<?php if (isset($block['data']['previewImage'])): ?>
    <?php do_action('block_image', __FILE__); ?>
<?php else: ?>
    <?php

    // Block helper
    require \get_template_directory() . '/template-parts/base/block-helper.php';
    if (isset($disable) && $disable) {
        return;
    }

    // Load values and assing defaults
    $sliders = get_field('slider') ?: false;
    $interval = intval(get_field('auto_swipe')) ?: 0;
?>
    <section class="section sliders-section block <?php echo $className; ?>" 
        <?php if ($bgUrl): ?>
            style="background-image: url('<?php echo $bgUrl; ?>');"
            data-desktop-image="<?php echo $bgUrl; ?>"
        <?php endif; ?>
        <?php if ($mobileBgUrl): ?>
            data-mobile-image="<?php echo $mobileBgUrl; ?>"
        <?php endif; ?>
        <?php if ($interval): ?>
            data-interval="<?php echo (int) $interval; ?>"
        <?php endif; ?>
        <?php if ($sectionId): ?>
            id="<?php echo $sectionId; ?>"
        <?php endif; ?>
    >
        <div class="container">
            <div class="col-md-10 offset-md-1 text-content">
                <?php if ($title): ?>
                    <h2 class="sub-title"><?php echo $title; ?></h2>
                <?php endif; ?>
                <?php if ($text): ?>
                    <div class="text text-center"><?php echo $text; ?></div>
                <?php endif; ?>
                <div class="sliders-slider mt-5">
                    <?php if (is_array($sliders) && $all = count($sliders)): ?>
                        <div class="sliders row">
                            <?php foreach ($sliders as $key => $slider): ?>
                                <div class="col-12 slider d-flex align-items-center <?php echo !$key ? 'active' : ''; ?> t<?php echo $key; ?>" data-no="<?php echo $key; ?>">
                                    <div class="row">
                                        <div class="col-md-7 order-last order-md-first d-flex align-items-center">
                                            <div>
                                                <?php if (array_key_exists('sub_title', $slider) && $subTitle = $slider['sub_title']): ?>
                                                    <div class="slider-sub-title text-center text-md-left"><?php echo $subTitle; ?></div>
                                                <?php endif; ?>
                                                <?php if (array_key_exists('title', $slider) && $title = $slider['title']): ?>
                                                    <h3 class="slider-title"><?php echo $title; ?></h3>
                                                <?php endif; ?>
                                                <?php if (array_key_exists('text', $slider) && $text = $slider['text']): ?>
                                                    <div class="text"><?php echo $text; ?></div>
                                                <?php endif; ?>
                                                <?php if (array_key_exists('cta', $slider) && !empty($slider['cta'])): ?>
                                                    <a href="<?php echo $slider['cta']['url']; ?>" target="<?php echo $slider['cta']['target']; ?>" class="cta btn btn-primary">
                                                        <?php echo $slider['cta']['title']; ?>
                                                    </a>
                                                <?php endif; ?>
                                            </div>
                                        </div>
                                        <div class="col-md-5 d-flex align-items-center">
                                            <?php if (array_key_exists('image', $slider) && $imageId = $slider['image']): ?>
                                                <?php echo wp_get_attachment_image($imageId, 'post-thumb', false, ['class' => 'slider-image']); ?>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                </div>
                            <?php endforeach; ?>
                        </div>

                        <div class="sliders-controller d-flex justify-content-between align-items-center">
                            <div class="numbers light"><span class="change">1</span> <small>/</small> <?php echo count($sliders);?></div>
                            <div class="controllers text-right">
                                <span class="controller ba-prev btn btn-primary" role="button" data-action="prew">
                                    <i class="fas fa-angle-left ba-prev" aria-label="Previous"></i>
                                </span>
                                <span class="controller ba-next btn btn-primary" role="button" data-action="next">
                                    <i class="fas fa-angle-right ba-next" aria-label="Next"></i>
                                </span>
                            </div>
                        </div>

                    <?php endif; ?>
                </div>
            </div>
        </div>
    </section>
<?php endif; ?>

