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

defined( 'ABSPATH' ) || exit;

use Errigal\Constant\{
	Errigal_Html_Attr as Html_Attr,
	Errigal_Html_Option as Html_Option,
	Errigal_Navigation_Class as Navigation_Class,
	Errigal_Navigation_Id as Navigation_Id,
	Errigal_Shared_Class as Shared_Class
};
use Errigal\Icon\Errigal_Icon as Icon;
use Errigal\Search\Errigal_Search_Form as Search_Form;
use Errigal\Shared\Errigal_Html_Builder as Html_Builder;

$html_builder = Html_Builder::create();

if ( wp_is_mobile() ) {
	$html_builder->create_button(
		array(
			Html_Option::ATTRS => array(
				Html_Attr::CLASS_NAME    => array(
					Navigation_Class::MOBILE_NAVIGATION_BUTTON,
					'mobile-navigation__search-button',
				),
				Html_Attr::TYPE          => Html_Attr::VALUE_BUTTON,
				Html_Attr::ARIA_CONTROLS => Navigation_Id::MOBILE_SEARCH,
				Html_Attr::ARIA_EXPANDED => false,
			),
		)
	)->render_element(
		function ( $html_builder ) {
			if ( ! Html_Builder::is_html_builder( $html_builder ) ) {
				return;
			}

			Icon::render_icon( Icon::SEARCH, Icon::SIZE_SM );
			$html_builder->create_div(
				array(
					Html_Option::ATTRS => array(
						Html_Attr::CLASS_NAME => Navigation_Class::MOBILE_NAVIGATION_BUTTON_TEXT,
					),
				)
			)->render_element(
				Search_Form::get_label()
			);
		}
	);

	return;
}

$html_builder->create_button(
	array(
		Html_Option::ATTRS => array(
			Html_Attr::CLASS_NAME    => array(
				Shared_Class::ICON_BUTTON,
				'site-header__search-button',
			),
			Html_Attr::TYPE          => Html_Attr::VALUE_BUTTON,
			Html_Attr::ARIA_LABEL    => Search_Form::get_label(),
			Html_Attr::ARIA_CONTROLS => Navigation_Id::SITE_HEADER_SEARCH,
			Html_Attr::ARIA_EXPANDED => false,
		),
	)
)->render_element(
	Icon::get_icon( Icon::SEARCH, Icon::SIZE_MD )
);
