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

function yoga_trainer_block_wrapper( $yoga_trainer_block_content, $yoga_trainer_block ) {

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

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

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

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

	}
    return $yoga_trainer_block_content;
}
	
add_filter( 'render_block', 'yoga_trainer_block_wrapper', 10, 2 );
