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

function yoga_workout_block_wrapper( $yoga_workout_block_content, $yoga_workout_block ) {

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

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

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

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

	}
    return $yoga_workout_block_content;
}
	
add_filter( 'render_block', 'yoga_workout_block_wrapper', 10, 2 );
