<?php
/**
 * Template part for displaying main navigation
 *
 * @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_Class as Navigation_Class,
};
use Errigal\Icon\Errigal_Icon as Icon;
use Errigal\Navigation\{
	Errigal_Main_Menu as Main_Menu,
	Errigal_Navigation as Navigation,
};
use Errigal\Shared\{
	Errigal_Html_Builder as Html_Builder,
	Errigal_Site_Info as Site_Info,
};

Html_Builder::create()->create_nav(
	array(
		Html_Option::ATTRS => array(
			Html_Attr::ID         => 'mobile-navigation',
			Html_Attr::CLASS_NAME => 'bottom-navbar',
			Html_Attr::ARIA_LABEL => Navigation::get_main_navigation_name(),
		),
	)
)->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 => 'mobile-navigation__container',
								),
							)
						)->render_element(
							function ( $html_builder ) {
								if ( ! $html_builder->is_html_builder( $html_builder ) ) {
									return;
								}

								$html_builder->create_a(
									array(
										Html_Option::ATTRS => array(
											Html_Attr::CLASS_NAME => array(
												Navigation_Class::MOBILE_NAVIGATION_BUTTON,
												'mobile-navigation__home-button',
											),
											Html_Attr::HREF => Site_Info::get_home_url(),
										),
									)
								)->render_element(
									function ( $html_builder ) {
										if ( ! $html_builder->is_html_builder( $html_builder ) ) {
											return;
										}

										Icon::render_icon( Icon::HOME, Icon::SIZE_SM );
										$html_builder->create_div(
											array(
												Html_Option::ATTRS => array(
													Html_Attr::CLASS_NAME => Navigation_Class::MOBILE_NAVIGATION_BUTTON_TEXT,
												),
											)
										)->render_element(
											Site_Info::get_home_link_text()
										);
									}
								);
								get_template_part( 'template-parts/component/search/search-button' );

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