<?php

/**
 * Check emphasis 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-check-emphasis';

if (! empty($block['className'])) {
  $class_name .= ' ' . $block['className'];
}
if (! empty($block['align'])) {
  $class_name .= ' align' . $block['align'];
}

$innerBlocksTemplate = array(
  array(
    'core/heading',
    array(
      "level" => 3,
      "style" => array(
        "typography" => array(
          "fontStyle" => "normal",
          "fontWeight" => "600",
        ),
        "spacing" => array(
          "margin" => array(
            "top" => "var:preset|spacing|20",
            "bottom" => "var:preset|spacing|20",
          ),
        ),
      ),
      "fontSize" => "large",
      "placeholder" => "Item title"
    )
  ),
  array(
    'core/paragraph',
    array(
      "style" => array(
        "spacing" => array(
          "margin" => array(
            "top" => "0",
            "bottom" => "0",
          ),
        ),
      ),
      "placeholder" => "Lorem ipsum dolor sit amet naect sum nam"
    )
  ),
);

$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)";
?>
<div <?php echo $anchor; ?>class="<?php echo esc_attr($class_name); ?>">
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" style="background:<?php echo $primary_color ?>;fill:<?php echo $primary_contrast_color ?>;">
    <path d="M438.6 105.4c12.5 12.5 12.5 32.8 0 45.3l-256 256c-12.5 12.5-32.8 12.5-45.3 0l-128-128c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0L160 338.7 393.4 105.4c12.5-12.5 32.8-12.5 45.3 0z" />
  </svg>
  <div class="olympus-check-emphasis-content">
    <InnerBlocks template="<?php echo esc_attr(wp_json_encode($innerBlocksTemplate)) ?>" />
  </div>
</div>