<?php 
/* 
* Block Name: Mozaik
* 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
    $mozaik = get_field('mozaik') ?: false;
?>
    <section class="section mozaik-section-wrapper 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="row g-0">
            <?php if ($mozaik && is_array($mozaik)): ?>
                <?php foreach ($mozaik as $no => $pice): ?>
                    <?php if (is_array($pice)): ?>
                        <div class="col-lg-6"> 
                            <div class="row g-0 d-md-flex align-items-center <?php echo array_key_exists('background_color', $pice) ? $pice['background_color'] : ''; ?>">
                                <div class="col-lg-6 <?php echo in_array($no, [2,3,6,7,10,11,14,15]) ? 'order-lg-2' : ''; ?>">
                                    <?php if (array_key_exists('image', $pice) && $imgId = $pice['image']): ?>
                                        <?php echo wp_get_attachment_image($imgId, 'profile', false, ['class' => 'image']); ?>
                                    <?php endif; ?>
                                </div>
                                <div class="col-md-6 p-4">
                                    <?php if (array_key_exists('label', $pice) && $label = $pice['label']): ?>
                                        <h2 class="h3"><?php echo $label; ?></h2>
                                    <?php endif; ?>
                                    <?php if (array_key_exists('text', $pice) && $text = $pice['text']): ?>
                                        <div class="text"><?php echo $text; ?></div>
                                    <?php endif; ?>
                                    <?php if (array_key_exists('link', $pice) && is_array($pice['link']) && $link = $pice['link']): ?>
                                        <a href="<?php echo $link['url']; ?>" target="<?php echo $link['target']; ?>" class="link"><?php echo $link['title']; ?></a>
                                    <?php endif; ?>
                                </div>
                            </div>
                        </div>
                    <?php endif; ?>
                <?php endforeach; ?>
            <?php endif; ?>
        </div>
    </section>
<?php endif; ?>

