<?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		5.3.3
 * @version		6.2.8
 */

namespace WeCodeArt\Gutenberg\Blocks\Comment\Pagination;

defined( 'ABSPATH' ) || exit;

use WeCodeArt\Singleton;
use WeCodeArt\Gutenberg\Blocks\Dynamic;
use WeCodeArt\Gutenberg\Blocks\Comment\Template;
use function WeCodeArt\Functions\get_prop;

/**
 * Gutenberg Pagination Numbers block.
 */
class Numbers extends Dynamic {

	use Singleton;

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

	/**
	 * Block name.
	 *
	 * @var string
	 */
	protected $block_name = 'comments-pagination-numbers';

	/**
	 * Block args.
	 *
	 * @return 	array
	 */
	public function init() {
		\add_filter( 'render_block_' . $this->get_block_type(), [ $this, 'render' ], 20, 1 );
	}

	/**
	 * Block args.
	 *
	 * @return 	array
	 */
	public function block_type_args(): array {
		return [
			'style'	=> [ $this->get_asset_handle(), 'wp-block-query-pagination-numbers' ]
		];
	}

	/**
	 * Dynamically renders the `core/comments-pagination-numbers` block.
	 *
	 * @param 	string 	$content 	The block markup.
	 *
	 * @return 	string 	The block markup.
	 */
	public function render( string $content = '' ): string {
		if( ! $content ) {
			return $content;
		}

        $p = wecodeart( 'dom' )::processor( $content );
		
		if( $p->next_tag( [
			'class_name'	=> 'wp-block-comments-pagination-numbers',
		] ) ) {
			$p->add_class( 'wp-block-query-pagination-numbers' );
		}

		$content = $p->get_updated_html();

		$pagination_numbers = wecodeart( 'blocks' )->get( 'core/query-pagination-numbers' )::get_instance();

		return $pagination_numbers->format_pagination( $content );
	}

	/**
	 * Block styles
	 *
	 * @return 	string 	The block styles.
	 */
	public function styles() {
		return <<<CSS
			.wp-block-comments-pagination-numbers:only-child {
				margin-bottom: 0!important;
			}
		CSS;
	}
}
