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

function pixel_watch_center_block_wrapper( $pixel_watch_center_block_content, $pixel_watch_center_block ) {

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

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

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

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

	}
    return $pixel_watch_center_block_content;
}
	
add_filter( 'render_block', 'pixel_watch_center_block_wrapper', 10, 2 );
