<?php

/**
 * Icon card 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-icon-card';
$style = '';

$wrapper_attributes = get_block_wrapper_attributes(
  [
    'class' => $class_name,
    'style' => $style
  ]
);
$icon = get_field('icon');
if ($icon) {
  $icon = file_get_contents(get_template_directory() . '/admin/img/acf/' . $icon . '.svg');
}

$innerBlocksTemplate = array(
  array(
    'core/heading',
    array(
      "level" => 4,
      "style" => array(
        "typography" => array(
          "fontStyle" => "normal",
          "fontWeight" => "600",
        ),
        "spacing" => array(
          "margin" => array(
            "top" => "var:preset|spacing|20",
            "bottom" => "var:preset|spacing|20",
          ),
        ),
      ),
      "textAlign" => ($context["acf/fields"]["theme"] === "accelerator") ? "left" : "center",
      "fontSize" => "large",
      "placeholder" => "Selling point"
    )
  ),
  array(
    'core/paragraph',
    array(
      "style" => array(
        "spacing" => array(
          "margin" => array(
            "top" => "0",
            "bottom" => "0",
          ),
        ),
      ),
      "align" => ($context["acf/fields"]["theme"] === "accelerator") ? "left" : "center",
      "placeholder" => "Lorem ipsum dolor sit amet naect sum nam"
    )
  ),
);
?>
<div <?php echo $anchor ?><?php echo $wrapper_attributes; ?>>
  <?php if ($icon): ?>
    <div class="olympus-icon-card-icon-wrap">
      <?php echo $icon ?>
    </div>
  <?php endif; ?>
  <InnerBlocks template="<?php echo esc_attr(wp_json_encode($innerBlocksTemplate)) ?>" />
</div>