<?php

/**
 * Home hero 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']) . '" ';
}

// Load values and assign defaults.
$class_name = 'olympus-home-hero alignfull';
$style = '';

$theme = get_field('theme');
if ($theme) {
  $class_name .= ' ' . $theme;
}

$background_image = (get_field('image')) ? get_field('image')['url'] : get_the_post_thumbnail_url();
$background_color = (get_field('background_color')) ? get_field('background_color') : 'var(--wp--preset--color--secondary)';
$has_overflow = (get_field('has_overflow')) ? ' has-overflow' : '';
$class_name .= $has_overflow;

if ($theme !== 'triumph' && $background_image) {
  $style .= 'background-image:url("' . $background_image . '");';
}
if ($theme == 'triumph' && $background_color) {
  $style .= 'background:' . $background_color . ';';
}

$wrapper_attributes = get_block_wrapper_attributes(
  [
    'class' => $class_name,
    'style' => $style
  ]
);
$overlay_opacity = (get_field('overlay_opacity')) ? get_field('overlay_opacity') : 0.65;
$selling_points_background_color = (get_field('selling_points_background_color')) ? get_field('selling_points_background_color') : 'var(--wp--preset--color--primary)';
$selling_points_color = (get_field('selling_points_color')) ? get_field('selling_points_color') : '#ffffff';
?>
<div <?php echo $anchor ?><?php echo $wrapper_attributes; ?>>
  <div class="olympus-home-hero-overlay" style="opacity:<?php echo $overlay_opacity ?>;"></div>
  <InnerBlocks />
  <?php if ($theme == 'triumph'): ?>
    <div class="olympus-home-hero-img">
      <img src="<?php echo $background_image ?>" />
    </div>
  <?php endif; ?>
</div>
<?php if ($theme == 'ace'): ?>
  <?php
  if (have_rows('selling_points')):
  ?>
    <div class="olympus-home-hero-points alignfull" style="background-color:<?php echo $selling_points_background_color ?>;">
      <?php
      while (have_rows('selling_points')) : the_row();
        $item = get_sub_field('item');
        if ($item):
      ?>
          <div class="olympus-home-hero-point" style="color:<?php echo $selling_points_color ?>;">
            <svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" height="16" viewBox="0 0 448 512">
              <path d="M441 103c9.4 9.4 9.4 24.6 0 33.9L177 401c-9.4 9.4-24.6 9.4-33.9 0L7 265c-9.4-9.4-9.4-24.6 0-33.9s24.6-9.4 33.9 0l119 119L407 103c9.4-9.4 24.6-9.4 33.9 0z" />
            </svg>
            <span><?php echo $item ?></span>
          </div>
      <?php
        endif;
      endwhile;
      ?>
    </div>
  <?php
  endif;
  ?>
<?php endif; ?>