<?php
/**
 * Block Filters
 *
 * @package futuristic_vision
 * @since 1.0
 */

function futuristic_vision_block_wrapper( $futuristic_vision_block_content, $futuristic_vision_block ) {

	if ( 'core/button' === $futuristic_vision_block['blockName'] ) {
		
		if( isset( $futuristic_vision_block['attrs']['className'] ) && strpos( $futuristic_vision_block['attrs']['className'], 'has-arrow' ) ) {
			$futuristic_vision_block_content = str_replace( '</a>', futuristic_vision_get_svg( array( 'icon' => esc_attr( 'caret-circle-right' ) ) ) . '</a>', $futuristic_vision_block_content );
			return $futuristic_vision_block_content;
		}
	}

	if( ! is_single() ) {
	
		if ( 'core/post-terms'  === $futuristic_vision_block['blockName'] ) {
			if( 'post_tag' === $futuristic_vision_block['attrs']['term'] ) {
				$futuristic_vision_block_content = str_replace( '<div class="taxonomy-post_tag wp-block-post-terms">', '<div class="taxonomy-post_tag wp-block-post-terms flex">' . futuristic_vision_get_svg( array( 'icon' => esc_attr( 'tags' ) ) ), $futuristic_vision_block_content );
			}

			if( 'category' ===  $futuristic_vision_block['attrs']['term'] ) {
				$futuristic_vision_block_content = str_replace( '<div class="taxonomy-category wp-block-post-terms">', '<div class="taxonomy-category wp-block-post-terms flex">' . futuristic_vision_get_svg( array( 'icon' => esc_attr( 'category' ) ) ), $futuristic_vision_block_content );
			}
			return $futuristic_vision_block_content;
		}
		if ( 'core/post-date' === $futuristic_vision_block['blockName'] ) {
			$futuristic_vision_block_content = str_replace( '<div class="wp-block-post-date">', '<div class="wp-block-post-date flex">' . futuristic_vision_get_svg( array( 'icon' => esc_attr( 'calendar' ) ) ), $futuristic_vision_block_content );
			return $futuristic_vision_block_content;
		}
		if ( 'core/post-author' === $futuristic_vision_block['blockName'] ) {
			$futuristic_vision_block_content = str_replace( '<div class="wp-block-post-author">', '<div class="wp-block-post-author flex">' . futuristic_vision_get_svg( array( 'icon' => esc_attr( 'user' ) ) ), $futuristic_vision_block_content );
			return $futuristic_vision_block_content;
		}
	}
	if( is_single() ){

		// Add chevron icon to the navigations
		if ( 'core/post-navigation-link' === $futuristic_vision_block['blockName'] ) {
			if( isset( $futuristic_vision_block['attrs']['type'] ) && 'previous' === $futuristic_vision_block['attrs']['type'] ) {
				$futuristic_vision_block_content = str_replace( '<span class="post-navigation-link__label">', '<span class="post-navigation-link__label">' . futuristic_vision_get_svg( array( 'icon' => esc_attr( 'prev' ) ) ), $futuristic_vision_block_content );
			}
			else {
				$futuristic_vision_block_content = str_replace( '<span class="post-navigation-link__label">Next Post', '<span class="post-navigation-link__label">Next Post' . futuristic_vision_get_svg( array( 'icon' => esc_attr( 'next' ) ) ), $futuristic_vision_block_content );
			}
			return $futuristic_vision_block_content;
		}
		if ( 'core/post-date' === $futuristic_vision_block['blockName'] ) {
            $futuristic_vision_block_content = str_replace( '<div class="wp-block-post-date">', '<div class="wp-block-post-date flex">' . futuristic_vision_get_svg( array( 'icon' => 'calendar' ) ), $futuristic_vision_block_content );
            return $futuristic_vision_block_content;
        }
		if ( 'core/post-author' === $futuristic_vision_block['blockName'] ) {
            $futuristic_vision_block_content = str_replace( '<div class="wp-block-post-author">', '<div class="wp-block-post-author flex">' . futuristic_vision_get_svg( array( 'icon' => 'user' ) ), $futuristic_vision_block_content );
            return $futuristic_vision_block_content;
        }

	}
    return $futuristic_vision_block_content;
}
	
add_filter( 'render_block', 'futuristic_vision_block_wrapper', 10, 2 );
