<?php
/**
 * Template part for displaying content of search
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/#search-result
 *
 * @package errigal
 * @since 1.0.0
 */

defined( 'ABSPATH' ) || exit;

use Errigal\Constant\Errigal_Template_Part as Template_Part;
use Errigal\Shared\Errigal_Html_Builder as Html_Builder;

if ( have_posts() ) {
	get_template_part(
		'template-parts/header/page-header',
		null,
		array(
			Template_Part::HEADING => sprintf(
				/* translators: %s: Search query. */
				esc_html__( 'Search Results for: %s', 'errigal' ),
				Html_Builder::create()->create_b()->get_element(
					esc_html( get_search_query() )
				)
			),
		)
	);
	get_template_part( 'template-parts/component/content/post-list' );
	get_template_part( 'template-parts/component/content/posts-pagination' );

	return;
}

get_template_part(
	'template-parts/component/content/no-entry-section',
	null,
	array(
		/**
		 * Renders no entry section content.
		 *
		 * @since 1.1.0
		 *
		 * @return void
		 */
		Template_Part::RENDER_CALLBACK => function () {
			get_template_part( 'template-parts/header/page-header-nothing-found' );
			get_template_part(
				'template-parts/component/content/page-content',
				null,
				array(
					/**
					 * Renders page content.
					 *
					 * @since 1.1.0
					 *
					 * @return void
					 */
					Template_Part::RENDER_CALLBACK => function () {
						$html_builder = Html_Builder::create();

						$html_builder->create_h2()->render_element(
							sprintf(
								/* translators: %s: Search query. */
								esc_html__( 'Keyword: %s', 'errigal' ),
								$html_builder->create_b()->get_element(
									esc_html( get_search_query() )
								)
							)
						);
						$html_builder->create_p()->render_element(
							esc_html__( 'Please try again with different keywords.', 'errigal' )
						);
						get_search_form();
					},
				)
			);
		},
	)
);
