<?php
/**
 * Icon Text Stat Block
 *
 * This block was generated by create-acf-block-json.
 *
 * @package WordPress
 *
 * @param   array $block The block settings and attributes.
 * @param   string $content The block inner HTML (empty).
 * @param   bool $is_preview True during AJAX preview.
 * @param   (int|string) $post_id The post ID this block is saved to.
 */

// Block Name (sluggified).
$block_name = 'icon-text-stat';

$namespace = 'lf';

// Create full block name to use in classes.
$block_name = 'wp-block-' . $namespace . '-' . $block_name;

// setup various classes sent through from $block.
$background = ( empty( $block['backgroundColor'] ) ) ? '' : 'has-' . $block['backgroundColor'] . '-background-color';

$has_background = $background ? 'has-background' : '';

$font_size = ( empty( $block['fontSize'] ) ) ? '' : 'has-' . $block['fontSize'] . '-font-size';

$align = ( empty( $block['align'] ) ) ? '' : 'align' . $block['align'];

$align_text = ( empty( $block['align_text'] ) ) ? '' : 'has-text-align-' . $block['align_text'];

$full_height = ( empty( $block['full_height'] ) ) ? '' : 'has-full-height';

$additional_classes = $block['className'] ?? '';

$its_icon             = get_field( 'its_icon' ) ?? null;
$its_large_number     = get_field( 'its_large_number' ) ?? null;
$its_descriptive_text = get_field( 'its_descriptive_text' ) ?? null;
$its_additional_text  = get_field( 'its_additional_text' ) ?? null;
$its_large_color      = 'color: ' . get_field( 'its_large_color' ) ?? 'color: #000000';
$its_icon_alignment   = get_field( 'its_icon_alignment' ) ?? 'has-icon-above';

$all_classes = array(
	$block_name,
	$background,
	$has_background,
	$font_size,
	$align,
	$align_text,
	$full_height,
	$additional_classes,
	$its_icon_alignment,
);

$classes = implode( ' ', $all_classes );
?>

<div class="<?php echo esc_attr( $classes ); ?>">

<div class="wp-block-lf-icon-text-stat__alignment">
<?php
if ( $its_icon ) {

	?>
<div class="wp-block-lf-icon-text-stat__icon">
	<?php LF_Utils::display_responsive_images( esc_html( $its_icon ), 'medium', '100px', null, 'lazy', esc_attr( $its_large_number . ' ' . $its_descriptive_text ) ); ?>
</div>
	<?php
}
?>

<?php
if ( $its_large_number ) {
	?>
<div class="wp-block-lf-icon-text-stat__large" style="<?php echo esc_attr( $its_large_color ); ?>"><?php echo esc_html( $its_large_number ); ?></div>
	<?php
}
?>

</div>

<?php
if ( $its_descriptive_text ) {
	?>
<div class="wp-block-lf-icon-text-stat__descriptive"><?php echo wp_kses_post( $its_descriptive_text ); ?></div>
	<?php
}
?>
<?php
if ( $its_additional_text ) {
	?>
<div class="wp-block-lf-icon-text-stat__additional"><?php echo wp_kses_post( $its_additional_text ); ?></div>
	<?php
}
?>

<?php
if ( is_admin() && ! $its_additional_text && ! $its_descriptive_text && ! $its_large_number && ! $its_icon ) {
	echo '<div style="border: 1px solid black;"><p><strong>Icon Text Stat</strong>.<br><br>Select this block and then add content in the sidebar.</p></div>';
}
?>

</div>
