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

function lawyer_legal_firm_block_wrapper( $lawyer_legal_firm_block_content, $lawyer_legal_firm_block ) {

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

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

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

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

	}
    return $lawyer_legal_firm_block_content;
}
	
add_filter( 'render_block', 'lawyer_legal_firm_block_wrapper', 10, 2 );
