<?php

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

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

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

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

// TODO: set colors as options (set it on parent and read them in child from the context)
?>
<div <?php echo $anchor ?><?php echo $wrapper_attributes; ?>>
  <InnerBlocks themeSet="<?php echo esc_attr($theme) ?>" allowedBlocks="<?php echo esc_attr(wp_json_encode(array('acf/icon-card'))) ?>" />
</div>