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

function shoe_outlet_block_wrapper( $shoe_outlet_block_content, $shoe_outlet_block ) {

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

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

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

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

	}
    return $shoe_outlet_block_content;
}
	
add_filter( 'render_block', 'shoe_outlet_block_wrapper', 10, 2 );
