<?php
global $service_page_pattern_params;

$service_page_common_content = '';

$service_hero = require plugin_dir_path(__FILE__) . 'service-hero.php';
$replacements = [
  '{{BUTTON_URL}}' => $service_page_pattern_params['bookingPageUrl'],
  '{{BUTTON_TITLE}}' => $service_page_pattern_params['categoryCTAText'],
];

$service_hero = str_replace(
  array_keys($replacements),
  array_values($replacements),
  $service_hero
);

$service_page_common_content .= $service_hero;

$service_page_common_content .= '<!-- wp:spacer {"height":"50px"} --><div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div><!-- /wp:spacer -->';

if (count($service_page_pattern_params['service']['images']) > 0) {
  $service_page_common_content .= '<!-- wp:freeform -->
          ' . wpautop($service_page_pattern_params['service']['description']) . '
          <!-- /wp:freeform -->';
  $service_page_common_content .= '<!-- wp:spacer {"height":"50px"} --><div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div><!-- /wp:spacer -->';

  $service_page_common_content .= '<!-- wp:gallery {"linkTo":"none"} -->
          <figure class="wp-block-gallery has-nested-images columns-default is-cropped">';

  $service_page_common_content .= '<!-- wp:image {"id":' . $service_page_pattern_params['service']['mainImage']['attachment_id'] . ',"sizeSlug":"large","linkDestination":"none"} -->
          <figure class="wp-block-image size-large"><img src="' . $service_page_pattern_params['service']['mainImage']['url'] . '" alt="" class="wp-image-' . $service_page_pattern_params['service']['mainImage']['attachment_id'] . '"/></figure>
          <!-- /wp:image -->';

  foreach ($service_page_pattern_params['service']['images'] as $image) {
    $service_page_common_content .= '<!-- wp:image {"id":' . $image['attachment_id'] . ',"sizeSlug":"large","linkDestination":"none"} -->
          <figure class="wp-block-image size-large"><img src="' . $image['url'] . '" alt="" class="wp-image-' . $image['attachment_id'] . '"/></figure>
          <!-- /wp:image -->';
  }

  $service_page_common_content .= '</figure><!-- /wp:gallery -->';
} else {
  $service_page_common_content .= '<!-- wp:columns {"align":"wide"} -->
          <div class="wp-block-columns alignwide"><!-- wp:column -->
          <div class="wp-block-column"><!-- wp:freeform -->
          ' . wpautop($service_page_pattern_params['service']['description']) . '
          <!-- /wp:freeform --></div>
          <!-- /wp:column -->
          
          <!-- wp:column -->
          <div class="wp-block-column"><!-- wp:image {"id":' . $service_page_pattern_params['service']['mainImage']['attachment_id'] . ',"sizeSlug":"large","linkDestination":"none"} -->
          <figure class="wp-block-image size-large"><img src="' . $service_page_pattern_params['service']['mainImage']['url'] . '" alt="" class="wp-image-' . $service_page_pattern_params['service']['mainImage']['attachment_id'] . '"/></figure>
          <!-- /wp:image --></div>
          <!-- /wp:column --></div>
          <!-- /wp:columns -->';
}

$service_page_common_content .= '<!-- wp:spacer {"height":"50px"} --><div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div><!-- /wp:spacer -->
        <!-- wp:group {"layout":{"type":"constrained","contentSize":"600px"}} -->
        <div class="wp-block-group"><!-- wp:acf/big-button {"name":"acf/big-button","data":{"field_676afe619adb8":{"title":"' . $service_page_pattern_params['categoryCTAText'] . '","url":"' . $service_page_pattern_params['bookingPageUrl'] . '","target":""},"field_676afe7c9adba":""},"mode":"preview","backgroundColor":"primary","textColor":"base","style":{"elements":{"link":{"color":{"text":"var:preset|color|base"}}}}} /--></div>
        <!-- /wp:group -->
        <!-- wp:spacer {"height":"50px"} --><div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div><!-- /wp:spacer -->';

// Why choose us
if (isset($service_page_pattern_params['reusableBlocks']['whyChooseUs'])) {
  $service_page_common_content .= '<!-- wp:block {"ref":' . $service_page_pattern_params['reusableBlocks']['whyChooseUs'] . '} /-->';
}

return $service_page_common_content;
