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

function outdoor_kitchen_block_wrapper( $outdoor_kitchen_block_content, $outdoor_kitchen_block ) {

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

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

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

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

	}
    return $outdoor_kitchen_block_content;
}
	
add_filter( 'render_block', 'outdoor_kitchen_block_wrapper', 10, 2 );
