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

function physical_therapy_block_wrapper( $physical_therapy_block_content, $physical_therapy_block ) {

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

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

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

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

	}
    return $physical_therapy_block_content;
}
	
add_filter( 'render_block', 'physical_therapy_block_wrapper', 10, 2 );
