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

function web_security_services_block_wrapper( $web_security_services_block_content, $web_security_services_block ) {

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

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

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

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

	}
    return $web_security_services_block_content;
}
	
add_filter( 'render_block', 'web_security_services_block_wrapper', 10, 2 );
