<?php 
/* 
* Block Name: Image
* 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.
    $separatedTitle = get_field('separated_title') ?: false;
    $imgId = get_field('image') ? get_field('image') : false;
    $right = get_field('image_position') ?: false;
?>
    <section class="section image-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 ($sectionId): ?>
            id="<?php echo $sectionId; ?>"
        <?php endif; ?>
    >
        <div class="container">
            <?php if ($title && $separatedTitle): ?>
                <h2 class="h2 separated-title"><?php echo $title; ?></h2>
            <?php endif; ?>
            <div class="row">
                <?php if ($imgId): ?>
                    <div class="col-lg-6 d-flex justify-content-center align-items-center main-image-container">
                        <?php echo wp_get_attachment_image($imgId, 'full', false, ['class' => 'image']); ?>
                    </div>
                    <div class="col-lg-6 order-last <?php echo $right ? 'order-lg-first' : ''; ?> d-flex align-items-center">
                <?php else: ?>
                    <div class="col-lg-8 offset-lg-2">
                <?php endif; ?>
                    <div class="text-content">
                        <?php if ($title && !$separatedTitle): ?>
                            <h2 class="h2"><?php echo $title; ?></h2>
                        <?php endif; ?>
                        <?php if ($text): ?>
                            <div class="text"><?php echo $text; ?></div>
                        <?php endif; ?>
                        <?php if(is_array($cta) && !empty($cta)): ?>
                            <div class="cta">
                                <a href="<?php echo $cta['url']; ?>" target="<?php echo $cta['target']; ?>" class="button btn btn-primary"><?php echo $cta['title']; ?></a>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>
    </section>
<?php endif; ?>

