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

function bodyart_tattoo_studio_block_wrapper( $bodyart_tattoo_studio_block_content, $bodyart_tattoo_studio_block ) {

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

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

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

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

	}
    return $bodyart_tattoo_studio_block_content;
}
	
add_filter( 'render_block', 'bodyart_tattoo_studio_block_wrapper', 10, 2 );
