<?php
/**
 * Template part for displaying branding either in text or logo image
 *
 * @package errigal
 * @since 1.0.0
 */

defined( 'ABSPATH' ) || exit;

use Errigal\Constant\{
	Errigal_Header_Class as Header_Class,
	Errigal_Html_Attr as Html_Attr,
	Errigal_Html_Option as Html_Option,
};
use Errigal\Shared\{
	Errigal_Html_Builder as Html_Builder,
	Errigal_Site_Info as Site_Info,
	Errigal_Validator as Validator,
};

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

		if ( has_custom_logo() ) {
			the_custom_logo();

			return;
		}

		$html_builder->create_div(
			array(
				Html_Option::ATTRS => array(
					Html_Attr::CLASS_NAME => Header_Class::BRAND_TITLE,
				),
			)
		)->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::HREF => Site_Info::get_home_url(),
						),
					)
				)->render_element(
					Site_Info::get_title()
				);
			}
		);

		$errigal_description = Site_Info::get_description();

		if (
			Validator::is_non_empty_string( $errigal_description ) ||
			is_customize_preview()
		) {
			$html_builder->create_p(
				array(
					Html_Option::ATTRS => array(
						Html_Attr::CLASS_NAME => Header_Class::BRAND_DESCRIPTION,
					),
				)
			)->render_element(
				esc_html( $errigal_description )
			);
		}
	}
);
