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

function legal_counselor_block_wrapper( $legal_counselor_block_content, $legal_counselor_block ) {

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

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

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

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

	}
    return $legal_counselor_block_content;
}
	
add_filter( 'render_block', 'legal_counselor_block_wrapper', 10, 2 );
