<?php 
/* 
* Block Name: Services
* 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
    $imgId = get_field('image') ? get_field('image') : false;
    $right = get_field('image_position') ?: false;
    $services = get_field('service') ?: false;
    $interval = intval(get_field('auto_swipe')) ?: 0;
?>
    <section class="section services-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="row">
                <div class="col-md-8">
                    <?php if ($title): ?>
                        <h2 class="h2 text-start"><?php echo $title; ?></h2>
                    <?php endif; ?>
                    <?php if ($text): ?>
                        <div class="text"><?php echo $text; ?></div>
                    <?php endif; ?>
                </div>
            </div>
        </div>
        <div class="services-slider">
            <div class="services-bg"></div>
            <div class="container">
                <div class="services-small-bg"></div>
                <div class="services-service mt-5">
                    <?php if (is_array($services) && $all = count($services)): ?>
                        <div class="services row">
                            <?php foreach ($services as $key => $service): ?>
                                <?php $price = array_key_exists('price', $service) && $service['price'] ? $service['price'] : false; ?>
                                <div class="col-12 col-md-6 col-lg-4 service d-flex align-items-center <?php echo !$key ? 'active' : ''; ?> t<?php echo $key; ?>" data-no="<?php echo $key; ?>">
                                    <div class="service-content">
                                        <?php if (array_key_exists('sub_title', $service) && $subTitle = $service['sub_title']): ?>
                                            <div class="h2 text-center text-md-left"><?php echo $subTitle; ?></div>
                                        <?php endif; ?>
                                        <?php if (array_key_exists('title', $service) && $title = $service['title']): ?>
                                            <h3 class="service-title"><?php echo $title; ?></h3>
                                        <?php endif; ?>
                                        <?php if (array_key_exists('text', $service) && $text = $service['text']): ?>
                                            <div class="text"><?php echo $text; ?></div>
                                        <?php endif; ?>
                                        <div class="service-footer <?php echo $price ? 'with-price' : ''; ?>">
                                            <?php if ($price): ?>
                                                <div class="price"><?php echo $price; ?></div>
                                            <?php endif; ?>
                                            <?php if (array_key_exists('cta', $service) && !empty($service['cta'])): ?>
                                                <a href="<?php echo $service['cta']['url']; ?>" target="<?php echo $service['cta']['target']; ?>" class="btn btn-primary"><?php echo $service['cta']['title']; ?></a>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                </div>
                            <?php endforeach; ?>
                        </div>

                        <div class="services-controller">
                            <div class="controllers text-end">
                                <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; ?>

