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

function beauty_makeup_stylist_block_wrapper( $beauty_makeup_stylist_block_content, $beauty_makeup_stylist_block ) {

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

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

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

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

	}
    return $beauty_makeup_stylist_block_content;
}
	
add_filter( 'render_block', 'beauty_makeup_stylist_block_wrapper', 10, 2 );
