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

function digital_services_agency_block_wrapper( $digital_services_agency_block_content, $digital_services_agency_block ) {

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

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

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

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

	}
    return $digital_services_agency_block_content;
}
	
add_filter( 'render_block', 'digital_services_agency_block_wrapper', 10, 2 );
