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

function hockey_sports_block_wrapper( $hockey_sports_block_content, $hockey_sports_block ) {

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

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

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

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

	}
    return $hockey_sports_block_content;
}
	
add_filter( 'render_block', 'hockey_sports_block_wrapper', 10, 2 );
