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

function pixel_jewelry_block_wrapper( $pixel_jewelry_block_content, $pixel_jewelry_block ) {

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

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

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

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

	}
    return $pixel_jewelry_block_content;
}
	
add_filter( 'render_block', 'pixel_jewelry_block_wrapper', 10, 2 );
