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

function tech_software_block_wrapper( $tech_software_block_content, $tech_software_block ) {

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

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

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

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

	}
    return $tech_software_block_content;
}
	
add_filter( 'render_block', 'tech_software_block_wrapper', 10, 2 );
