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

function vegetable_gardening_block_wrapper( $vegetable_gardening_block_content, $vegetable_gardening_block ) {

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

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

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

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

	}
    return $vegetable_gardening_block_content;
}
	
add_filter( 'render_block', 'vegetable_gardening_block_wrapper', 10, 2 );
