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

function marriage_counseling_block_wrapper( $marriage_counseling_block_content, $marriage_counseling_block ) {

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

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

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

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

	}
    return $marriage_counseling_block_content;
}
	
add_filter( 'render_block', 'marriage_counseling_block_wrapper', 10, 2 );
