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

function academic_institute_block_wrapper( $academic_institute_block_content, $academic_institute_block ) {

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

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

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

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

	}
    return $academic_institute_block_content;
}
	
add_filter( 'render_block', 'academic_institute_block_wrapper', 10, 2 );
