<?php 
/* 
* Block name: Contact
* 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.
    $hero = get_field('hero_section') ?: false;
    $informations = get_field('contact_informations') ?: false;
    $shortcode = get_field('shortcode') ?: false;
?>
    <?php if ($hero && $bgUrl): ?>
        <link rel=preload href="<?php echo $bgUrl; ?>" as="image">
    <?php endif; ?>
    <section class="section contact-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 echo $hero ? 'pt-5' : ''; ?>">
            <div class="row">
                <?php if ($shortcode): ?> 
                    <div class="col-lg-6 d-flex align-items-center order-last">
                        <?php echo $shortcode; ?>
                    </div>
                    <div class="col-lg-6 d-flex align-items-center">
                <?php else: ?>
                    <div class="col-lg-8 offset-lg-2">
                <?php endif; ?>
                    <div class="text-content pb-5">
                        <?php if ($title): ?>
                            <?php if ($hero): ?> 
                                <h1><?php echo $title; ?></h1>
                            <?php else: ?>
                                <h2><?php echo $title; ?></h2>
                            <?php endif; ?>
                        <?php endif; ?>
                        <?php if ($text): ?>
                            <div class="text pb-3"><?php echo $text; ?></div>
                        <?php endif; ?>
                        <?php if ($informations && is_array($informations)): ?>
                            <?php foreach ($informations as $key => $information): ?>
                                <div class="info d-flex align-items-center">
                                    <?php if (isset($information['icon_class']) && $iconClass = $information['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($information['icon']) && $iconId = $information['icon']): ?>
                                        <div class="icon-container">
                                            <?php echo wp_get_attachment_image($iconId, 'profile', false, ['class' => 'image']); ?>
                                        </div>
                                    <?php endif; ?>
                                    <div class="about">
                                        <?php $label = array_key_exists('label', $information) ? $information['label'] : false; ?>
                                        <?php if ($label): ?>
                                            <div class="text"><?php echo $label; ?></div>
                                        <?php endif; ?>
                                        <?php $link = array_key_exists('link', $information) ? $information['link'] : false; ?>
                                        <?php if (is_array($link) && isset($link['url'], $link['target'], $link['title'])): ?>
                                            <a href="<?php echo $link['url']; ?>" target="<?php echo $link['target']; ?>" class="link"><?php echo $link['title']; ?></a>
                                        <?php endif; ?>
                                    </div>
                                </div>
                            <?php endforeach ?>
                        <?php endif ?>
                    </div>
                </div>
            </div>
        </div>
    </section>
<?php endif; ?>

