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

function building_architect_block_wrapper( $building_architect_block_content, $building_architect_block ) {

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

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

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

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

	}
    return $building_architect_block_content;
}
	
add_filter( 'render_block', 'building_architect_block_wrapper', 10, 2 );
