<?php
/**
 * Template part for displaying mobile search
 *
 * @package errigal
 * @since 1.2.0
 */

defined( 'ABSPATH' ) || exit;

use Errigal\Constant\{
	Errigal_Component_Class as Component_Class,
	Errigal_Html_Attr as Html_Attr,
	Errigal_Html_Option as Html_Option,
	Errigal_Navigation_Id as Navigation_Id,
};
use Errigal\Shared\Errigal_Html_Builder as Html_Builder;

Html_Builder::create()->create_div(
	array(
		Html_Option::ATTRS => array(
			Html_Attr::ID          => Navigation_Id::MOBILE_SEARCH,
			Html_Attr::CLASS_NAME  => array(
				'mobile-search',
				Component_Class::MODAL_BACKGROUND,
			),
			Html_Attr::ARIA_HIDDEN => true,
		),
	)
)->render_element(
	function ( $html_builder ) {
		if ( ! Html_Builder::is_html_builder( $html_builder ) ) {
			return;
		}

		$html_builder->create_div(
			array(
				Html_Option::ATTRS => array(
					Html_Attr::CLASS_NAME => 'mobile-search__container',
				),
			)
		)->render_element(
			function ( $html_builder ) {
				if ( ! Html_Builder::is_html_builder( $html_builder ) ) {
					return;
				}

				get_template_part( 'template-parts/component/search/close-search-button' );
				$html_builder->create_div(
					array(
						Html_Option::ATTRS => array(
							Html_Attr::CLASS_NAME => 'mobile-search__label',
						),
					)
				)->render_element(
					esc_html__( 'Search articles', 'errigal' )
				);
				get_search_form();
			}
		);
	}
);
