<?php if (isset($block['data']['previewImage'])): ?>
    <?php echo blockImage(__FILE__); ?>
<?php else: ?>
    <?php
        // Enable script and style
        wp_enqueue_style('block-style-links');

        // Include helpers
        include get_template_directory() . '/inc/block-helper.php';

        // Get custom data
        $links = get_field('links') ?: false;
        $style = get_field('links_style') ?: 'blank';
    ?>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha512-DTOQO9RWCH3ppGqcWaEA1BIZOC6xxalwEsw9c2QQeAIftl+Vegovlnee1c9QX4TctnWMn13TZye+giMm8e2LwA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
    <section class="section links-section block <?php echo $className; ?>" id="<?php echo $sectionId; ?>">
        <div class="container">
            <div class="row">
                <div class="<?php echo $contentWidth ?: 'col-lg-8 offset-lg-2'; ?> text-content">
                    <?php if ($title): ?>
                        <h2 class="h2 text-center d-block"><?php echo $title; ?></h2>
                    <?php endif; ?>
                    <?php if ($text): ?>
                        <div class="text"><?php echo $text; ?></div>
                    <?php endif; ?>
                    <?php if ($links && is_array($links)): ?>
                        <div class="links pt-3 <?php echo $style; ?>">
                            <?php foreach ($links as $data): ?>
                                <?php 
                                    $link = array_key_exists('link', $data) ? $data['link'] : false;
                                    $icon = array_key_exists('icon', $data) ? $data['icon'] : 'fa-solid fa-arrow-up-right-from-square';
                                ?>
                                <a href="<?php echo $link['url']; ?>" target="<?php echo $link['target']; ?>" class="link d-flex justify-content-between align-items-center">
                                    <div class="label"><?php echo $link['title']; ?></div>
                                    <i class="icon <?php echo $icon; ?>"></i>
                                </a>
                            <?php endforeach; ?>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </section>
<?php endif; ?>
