<?php
/**
 * Template part for displaying site header inner content
 *
 * @package errigal
 * @since 1.0.0
 */

defined( 'ABSPATH' ) || exit;

use Errigal\Constant\{
	Errigal_Component_Class as Component_Class,
	Errigal_Header_Class as Header_Class,
	Errigal_Html_Attr as Html_Attr,
	Errigal_Html_Option as Html_Option,
	Errigal_Shared_Class as Shared_Class,
};
use Errigal\Navigation\Errigal_Main_Menu as Main_Menu;
use Errigal\Shared\Errigal_Html_Builder as Html_Builder;

$html_builder = Html_Builder::create();

$html_builder->create_div(
	array(
		Html_Option::ATTRS => array(
			Html_Attr::CLASS_NAME => Header_Class::SITE_HEADER_CONTAINER,
		),
	)
)->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 => Component_Class::CONTAINER,
				),
			)
		)->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 => Component_Class::ROW,
						),
					)
				)->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 => array(
										Header_Class::SITE_HEADER_CONTENT,
										Component_Class::COL_12,
									),
								),
							)
						)->render_element(
							function ( $html_builder ) {
								if ( ! Html_Builder::is_html_builder( $html_builder ) ) {
									return;
								}

								if ( wp_is_mobile() ) {
									get_template_part( 'template-parts/component/header/site-header/branding' );

									return;
								}

								$html_builder->create_div(
									array(
										Html_Option::ATTRS => array(
											Html_Attr::CLASS_NAME => Header_Class::SITE_HEADER_CONTENT_CONTAINER,
										),
									)
								)->render_element(
									function () {
										get_template_part( 'template-parts/component/header/site-header/branding' );
										get_template_part( 'template-parts/component/search/search-button' );
									}
								);

								if ( Main_Menu::can_show() ) {
									get_template_part( 'template-parts/component/navigation/menu-button' );
								}

								$html_builder->create_div(
									array(
										Html_Option::ATTRS => array(
											Html_Attr::CLASS_NAME => array(
												Shared_Class::ICON_BUTTON,
												'site-header__button-placeholder',
											),
											Html_Attr::ARIA_HIDDEN => true,
										),
									)
								)->render_element();
							}
						);

						if ( ! wp_is_mobile() ) {
							get_template_part( 'template-parts/component/search/site-header-search' );
						}
					}
				);
			}
		);
	}
);

if ( wp_is_mobile() ) {
	get_template_part( 'template-parts/component/search/mobile-search' );
	get_template_part( 'template-parts/component/navigation/mobile-navigation' );
} else {
	$html_builder->create_div(
		array(
			Html_Option::ATTRS => array(
				Html_Attr::CLASS_NAME => array(
					'site-header__search-background',
					Component_Class::MODAL_BACKGROUND,
				),
			),
		)
	)->render_element();
}

if ( Main_Menu::can_show() ) {
	get_template_part( 'template-parts/component/navigation/main-navigation' );
}
