<?php

/**
 * Multiple booking pages Block Template.
 *
 * @param   array $block The block settings and attributes.
 * @param   string $content The block inner HTML (empty).
 * @param   bool $is_preview True during backend preview render.
 * @param   int $post_id The post ID the block is rendering content against.
 *          This is either the post ID currently being displayed inside a query loop,
 *          or the post ID of the post hosting this block.
 * @param   array $context The context provided to the block by the post or it's parent block.
 */

// Support custom "anchor" values.
$anchor = '';
if (! empty($block['anchor'])) {
  $anchor = 'id="' . esc_attr($block['anchor']) . '" ';
}

// Create class attribute allowing for custom "className" and "align" values.
$class_name = 'olympus-multiple-booking-pages';
if (! empty($block['className'])) {
  $class_name .= ' ' . $block['className'];
}
if (! empty($block['align'])) {
  $class_name .= ' align' . $block['align'];
}

// TODO: validate this block
?>
<div <?php echo $anchor; ?>class="<?php echo esc_attr($class_name); ?>">
  <div class="olympus-multiple-booking-pages-buttons-wrap">
    <InnerBlocks />
    <div class="olympus-multiple-booking-pages-buttons">
      <?php
      if (have_rows('booking_pages')):
        while (have_rows('booking_pages')) : the_row();
          $code = get_sub_field('code');
          $button_label = get_sub_field('button_label');
      ?>
          <div class="wp-block-button">
            <a href="javascript:void(0);" class="wp-block-button__link wp-element-button" data-script="<?php echo base64_encode($code) ?>"><?php echo $button_label ?></a>
          </div>
      <?php
        endwhile;
      endif;
      ?>
    </div>
  </div>
  <div id="olympus-multiple-booking-pages-booking-page-wrap"></div>
</div>