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

function yoga_master_block_wrapper( $yoga_master_block_content, $yoga_master_block ) {

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

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

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

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

	}
    return $yoga_master_block_content;
}
	
add_filter( 'render_block', 'yoga_master_block_wrapper', 10, 2 );
