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

function kindergarten_preschool_block_wrapper( $kindergarten_preschool_block_content, $kindergarten_preschool_block ) {

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

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

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

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

	}
    return $kindergarten_preschool_block_content;
}
	
add_filter( 'render_block', 'kindergarten_preschool_block_wrapper', 10, 2 );
