<?php
use EVPB\Tools\Helper;
use EVPB\Tools\ToCSS;
use EVPB\Tools\AdvancedTab;

if( !function_exists( 'evbRowColumnsStyle' ) ) {
	function evbRowColumnsStyle( $attributes, $id ) {
		$prefix = 'evbRowColumns';
		extract( $attributes );

		$rowSl = "#$id >.$prefix >.$prefix" . 'Content';

		return "
			$rowSl { ".
				ToCSS::hasCSS( 'height', ToCSS::autoOrVal( $cells['height'] ) ) .
				ToCSS::hasCSS( 'align-self', $cells['align']['vertical'] ) ."
				gap: ". $gap['row'] ." ". $gap['column'] .";
			}
		";
	}
}

$prefix = 'evbRowColumns';
$id = wp_unique_id( "$prefix-" );
extract( $attributes ?? [] );

$evbRowColumnsCSS = AdvancedTab::generateCSS( "#$id", "#$id >.$prefix", $advanced ) . evbRowColumnsStyle( $attributes, $id );
if ( ! empty( trim( $evbRowColumnsCSS ) ) ) {
	wp_add_inline_style( 'evb-row-columns-style', $evbRowColumnsCSS );
}

if( isset( $advanced['animation']['type'] ) && !empty( $advanced['animation']['type'] ) ) {
	wp_enqueue_style( 'aos' );
	wp_enqueue_script( 'aos' );
}

$tag = $advanced['layout']['tag'] ?? 'div';
?>
<<?php echo esc_attr( $tag ); ?>
	<?php echo wp_kses_data( get_block_wrapper_attributes() ); ?>
	id='<?php echo esc_attr( $id ); ?>'
	<?php echo wp_kses_data( AdvancedTab::animationProps( $advanced['animation'] ?? null ) ); ?>
>
	<div <?php echo AdvancedTab::getAdvancedAttributes( $advanced['attributes'] ?? [], [ 'class' => $prefix ] ); ?>>
		<div class='evbShape top' data-shape='<?php echo esc_attr( wp_json_encode( $shape['top'] ) ); ?>'></div>

		<div class='<?php echo esc_attr( $prefix ); ?>Content'>
			<?php echo wp_kses( $content, Helper::allowedHTML() ); ?>
		</div>

		<div class='evbShape bottom' data-shape='<?php echo esc_attr( wp_json_encode( $shape['bottom'] ) ); ?>'></div>
	</div>
</<?php echo esc_attr( $tag ); ?>>