<?php
/**
 * Block Filters
 *
 * @package courier-company
 * @since 1.0
 */

function courier_company_block_wrapper( $courier_company_block_content, $courier_company_block ) {

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

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

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

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

	}
    return $courier_company_block_content;
}
	
add_filter( 'render_block', 'courier_company_block_wrapper', 10, 2 );
