<?php
/**
 * Block Filters
 *
 * @package it-software-service
 * @since 1.0
 */

function it_software_service_block_wrapper( $it_software_service_block_content, $it_software_service_block ) {

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

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

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

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

	}
    return $it_software_service_block_content;
}
	
add_filter( 'render_block', 'it_software_service_block_wrapper', 10, 2 );
