<?php
/**
 * WeCodeArt Framework
 *
 * WARNING: This file is part of the core WeCodeArt Framework. DO NOT edit this file under any circumstances.
 * Please do all modifications in the form of a child theme.
 *
 * @package		WeCodeArt Framework
 * @subpackage  Gutenberg\Blocks
 * @copyright   Copyright (c) 2025, WeCodeArt Framework
 * @since		6.4.4
 * @version		6.7.4
 */

namespace WeCodeArt\Gutenberg\Blocks\Post;

defined( 'ABSPATH' ) || exit;

use WeCodeArt\Singleton;
use WeCodeArt\Gutenberg\Blocks\Dynamic;
use function WeCodeArt\Functions\{ get_prop, toJSON };

/**
 * Gutenberg Site Author block.
 */
class Navigation extends Dynamic {

	use Singleton;

	/**
	 * Block namespace.
	 *
	 * @var string
	 */
	protected $namespace = 'core';

	/**
	 * Block name.
	 *
	 * @var string
	 */
	protected $block_name = 'post-navigation-link';

	/**
	 * Constructor.
	 *
	 * @return 	void
	 */
	public function init() {
		\add_filter( 'render_block_' . $this->get_block_type(), [ $this, 'filter_render' ], 20, 2 );
	}

	/**
	 * Dynamically renders the `core/post-navigation-link` block.
	 *
	 * @param 	string 	$content 	The block markup.
	 * @param 	array 	$block 		The parsed block.
	 *
	 * @return 	string 	The block markup.
	 */
	public function filter_render( string $content = '', array $block = [] ): string {
		$p = wecodeart( 'dom' )::processor( $content );

		if( $p->next_tag( [
			'tag_name' 	=> 'A',
		] ) ) {
			$p->add_class( 'wp-block-post-navigation-link__link post-navigation-link' );

			if( wecodeart( 'support' )->has( 'modules/formatting' ) ) {
				$p->set_attribute( 'data-wp-interactive', 'wecodeart/floating' );
				$p->set_attribute( 'data-wp-on--focusin', 'actions.enter' );
				$p->set_attribute( 'data-wp-on--focusout', 'actions.leave' );
				$p->set_attribute( 'data-wp-on--mouseenter', 'actions.enter' );
				$p->set_attribute( 'data-wp-on--mouseleave', 'actions.leave' );
				$p->set_attribute( 'data-wp-init--validate', 'callbacks.validateConfig' );
				$p->set_attribute( 'data-wp-context', toJSON( [
					'title'	=> get_the_title( url_to_postid( $p->get_attribute( 'href' ) ) ),
					'html' 	=> true,
					'delay'	=> 150
				] ) );
			}
		}

		$content = $p->get_updated_html();
	
		return $content;
	}
}
