<?php

/**
 * Two Columns Text Block Template.
 *
 * @param   array $block The block settings and attributes.
 * @param   string $content The block inner HTML (empty).
 * @param   bool $is_preview True during AJAX preview.
 * @param   (int|string) $post_id The post ID this block is saved to.
 */

// Create id attribute allowing for custom "anchor" value.
$id = 'two-cols-text-' . $block['id'];
if( !empty($block['anchor']) ) {
    $id = $block['anchor'];
}

// Create class attribute allowing for custom "className" and "align" values.
$className = 'two-cols-text';
if( !empty($block['className']) ) {
    $className .= ' ' . $block['className'];
}

?>

<section id="<?php echo esc_attr($id); ?>" class="<?php echo esc_attr($className); ?>">

    <div class="col col__first">
        <div class="col__wrapper">
            <?php echo get_field( 'first_col_text', $block['id'] ); ?>
        </div>
    </div>

    <div class="col col__second">
        <div class="col__wrapper">
            <?php echo get_field( 'second_col_text', $block['id'] ); ?>
        </div>
    </div>

</section>

<?php printf( "<script>window.dispatchEvent( new Event('acf/loaded/two-cols-text'));</script>" );