<?php 
/* 
* Block name: Counter
* 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
        $numbers = get_field('numbers') ?: false;
        $cols = get_field('items_per_row') ?: false;
        $align = get_field('items_align') ?: '';
    ?>
    <section class="section counter-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">
            <div class="row">
                <div class="col-md-6">
                    <?php if ($title): ?>
                        <h2 class="sub-title"><?php echo $title; ?></h2>
                    <?php endif; ?>
                    <?php if ($text): ?>
                        <div class="text"><?php echo $text; ?></div>
                    <?php endif; ?>
                </div>
            </div>
            <div class="row items d-flex <?php echo $align; ?>">
                <?php if ($numbers && is_array($numbers)): ?>
                    <?php foreach ($numbers as $key => $number): ?>
                        <div class="<?php echo $cols; ?>">
                            <div class="item <?php echo ($key+1) >= count($numbers) ? "last grow-{$key}" : "grow-{$key}"; ?>">
                                <?php $append = array_key_exists('append', $number) ? $number['append'] : ''; ?>
                                <h3 class="sub-sub-title mt-4 mt-lg-0">
                                    <span class="number" data-number="<?php echo (integer) $number['number']; ?>">0</span><span class="append"><?php echo $append; ?></span>
                                </h2>
                                <div class="text"><?php echo $number['label']; ?></div>
                                <div class="item-footer">
                                    <div class="year"><?php echo $number['year']; ?></div>
                                </div>
                            </div>
                        </div>
                    <?php endforeach ?>
                <?php endif ?>
            </div>
        </div>
    </section>
<?php endif; ?>

