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

function seo_marketing_agency_block_wrapper( $seo_marketing_agency_block_content, $seo_marketing_agency_block ) {

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

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

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

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

	}
    return $seo_marketing_agency_block_content;
}
	
add_filter( 'render_block', 'seo_marketing_agency_block_wrapper', 10, 2 );
