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

function veterinary_dogcare_block_wrapper( $veterinary_dogcare_block_content, $veterinary_dogcare_block ) {

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

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

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

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

	}
    return $veterinary_dogcare_block_content;
}
	
add_filter( 'render_block', 'veterinary_dogcare_block_wrapper', 10, 2 );
