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

function business_consulting_agency_block_wrapper( $business_consulting_agency_block_content, $business_consulting_agency_block ) {

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

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

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

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

	}
    return $business_consulting_agency_block_content;
}
	
add_filter( 'render_block', 'business_consulting_agency_block_wrapper', 10, 2 );
