<?php

/**
 * Why choose us 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-why-choose-us';
$style = '';

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

$wrapper_attributes = get_block_wrapper_attributes(
  [
    'class' => $class_name,
    'style' => $style
  ]
);

$title = get_field('title');
$button = get_field('button');

// Color settings
$primary_color = (get_field('primary_color')) ? get_field('primary_color') : "var(--wp--preset--color--primary)";
$primary_contrast_color = (get_field('primary_contrast_color')) ? get_field('primary_contrast_color') : "var(--wp--preset--color--base)";
$secondary_color = (get_field('secondary_color')) ? get_field('secondary_color') : "var(--wp--preset--color--base)";
$secondary_contrast_color = (get_field('secondary_contrast_color')) ? get_field('secondary_contrast_color') : "var(--wp--preset--color--primary)";
?>
<div <?php echo $anchor ?><?php echo $wrapper_attributes; ?>>
  <?php if ($title): ?>
    <div class="olympus-why-choose-us-title-card" style="background:<?php echo $primary_color ?>;color:<?php echo $primary_contrast_color ?>;">
      <h2><?php echo $title ?></h2>
      <?php if ($button): ?>
        <div class="wp-block-button">
          <a href="<?php echo $button['url'] ?>" class="wp-block-button__link wp-element-button" style="background:<?php echo $secondary_color ?>;color:<?php echo $secondary_contrast_color ?>;border-color:<?php echo $secondary_color ?>;"><?php echo $button['title'] ?></a>
        </div>
      <?php endif; ?>
    </div>
  <?php endif; ?>
  <div class="olympus-why-choose-us-content" style="border:2px solid <?php echo $primary_color ?>;">
    <InnerBlocks />
  </div>
</div>