<?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_Navigation_Hook as Navigation_Hook,
	Errigal_Html_Attr as Html_Attr,
	Errigal_Html_Option as Html_Option,
	Errigal_Navigation_Id as Navigation_Id,
	Errigal_Shared_Class as Shared_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;

$html_builder = Html_Builder::create();

$html_builder->create_div(
	array(
		Html_Option::ATTRS => array(
			Html_Attr::CLASS_NAME => array(
				'main-navigation-background',
				Component_Class::MODAL_BACKGROUND,
			),
		),
	)
)->render_element();
$html_builder->create_nav(
	array(
		Html_Option::ATTRS => array(
			Html_Attr::ID         => 'main-navigation',
			Html_Attr::CLASS_NAME => Navigation::get_main_navigation_classes(),
			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::ID         => Navigation_Id::MENU_CONTAINER,
					Html_Attr::CLASS_NAME => array(
						'menu-container',
						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 => 'close-menu-button__container',
						),
					)
				)->render_element(
					function ( $html_builder ) {
						if ( ! Html_Builder::is_html_builder( $html_builder ) ) {
							return;
						}

						$html_builder->create_button(
							array(
								Html_Option::ATTRS => array(
									Html_Attr::CLASS_NAME => array(
										Shared_Class::ICON_BUTTON,
										'close-menu-button',
									),
									Html_Attr::TYPE       => Html_Attr::VALUE_BUTTON,
									Html_Attr::ARIA_LABEL => esc_attr__( 'Close menu', 'errigal' ),
								),
							)
						)->render_element(
							Icon::get_icon( Icon::TIMES )
						);
					}
				);
				$html_builder->create_div(
					array(
						Html_Option::ATTRS => array(
							Html_Attr::CLASS_NAME => Component_Class::ROW,
						),
					)
				)->render_element(
					function () {
						Main_Menu::render_menu();
						do_action( Navigation_Hook::AFTER_MAIN_MENU );
					}
				);
			}
		);
	}
);
