<?php 
/* 
* Block Name: Features
* 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;
    }
?>
    <section class="section features-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): ?>
                <h2 class="h2 d-block"><?php echo $title; ?></h2>
            <?php endif; ?>
            <?php if ($text): ?>
                <div class="text">
                    <?php echo $text; ?>
                </div>
            <?php endif; ?>
            <div class="row pt-4 g-4">
                <?php if ($features = get_field('features')): ?>
                    <?php foreach ($features as $key => $feature): ?>
                        <div class="col-lg-6 col-xl-4">
                            <div class="feature">
                                <div class="feature-header pb-3 d-flex align-items-center">
                                    <?php if (isset($feature['icon_class']) && $iconClass = $feature['icon_class']): ?>
                                        <div class="icon-container highlighted d-flex justify-content-center align-items-center">
                                            <i class="icon <?php echo $iconClass; ?>"></i>
                                        </div>
                                    <?php elseif (isset($feature['icon']) && $iconId = $feature['icon']): ?>
                                        <div class="icon-container">
                                            <?php echo wp_get_attachment_image($iconId, 'profile', false, ['class' => 'image']); ?>
                                        </div>
                                    <?php endif; ?>
                                    <?php if (isset($feature['title']) && $featureTitle = $feature['title']): ?>
                                        <h3 class="h4"><?php echo $featureTitle; ?></h3>
                                    <?php endif; ?>
                                </div>
                                <?php if (isset($feature['text']) && $featureText = $feature['text']): ?>
                                    <div class="text"><?php echo $featureText; ?></div>
                                <?php endif; ?>
                                <?php if (isset($feature['cta']) && $cta = $feature['cta']): ?>
                                    <div class="cta mt-2">
                                        <a href="<?php echo $cta['url']; ?>" target="<?php echo $cta['target']; ?>" class="button btn btn-silent"><?php echo $cta['title']; ?></a>
                                    </div>
                                <?php endif; ?>
                            </div>
                        </div>
                    <?php endforeach ?>
                <?php endif ?>
            </div>
        </div>
    </section>
<?php endif; ?>

