<?php
/**
 * Template for displaying site header
 *
 * This is the template that displays all of the <head> section and everything up until <div id="main">
 *
 * @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
 *
 * @package errigal
 * @since 1.0.0
 */

defined( 'ABSPATH' ) || exit;

use Errigal\Constant\{
	Errigal_Accessibility_Class as Accessibility_Class,
	Errigal_Component_Class as Component_Class,
	Errigal_Content_Class as Content_Class,
	Errigal_Content_Hook as Content_Hook,
	Errigal_Header_Hook as Header_Hook,
	Errigal_Html_Attr as Html_Attr,
	Errigal_Html_Option as Html_Option,
};
use Errigal\Customiser\Errigal_Custom_Typography as Typography;
use Errigal\Shared\{
	Errigal_Html_Builder as Html_Builder,
	Errigal_Site_Info as Site_Info,
	Errigal_Utility as Utility,
};

$html_builder = Html_Builder::create();

// ── HTML ────────────────────────────────────────────────
$html_builder->create_html(
	array(
		Html_Option::ATTRS => Utility::array_merge_deep(
			is_rtl()
				? array(
					Html_Attr::DIR => Html_Attr::VALUE_RTL,
				)
			: array(),
			array(
				Html_Attr::CLASS_NAME => Typography::get_font_size_class(),
			),
		),
	)
)->render_open_tag();
// ──── HEAD ──────────────────────────────────────────────
$html_builder->create_head()->render_element(
	function ( $html_builder ) {
		if ( ! Html_Builder::is_html_builder( $html_builder ) ) {
			return;
		}

		$html_builder->create_meta(
			array(
				Html_Option::ATTRS => array(
					Html_Attr::CHARSET => Site_Info::get_charset(),
				),
			)
		)->render_element();
		$html_builder->create_meta(
			array(
				Html_Option::ATTRS => array(
					Html_Attr::NAME    => 'viewport',
					Html_Attr::CONTENT => 'width=device-width, initial-scale=1',
				),
			)
		)->render_element();
		wp_head();
	}
);
// ──── BODY ──────────────────────────────────────────────
$html_builder->create_body(
	array(
		Html_Option::ATTRS => array(
			Html_Attr::CLASS_NAME => get_body_class(),
		),
	)
)->render_open_tag();
wp_body_open();
// ────── PAGE ────────────────────────────────────────────
$html_builder->create_div(
	array(
		Html_Option::ATTRS => array(
			Html_Attr::ID         => 'page',
			Html_Attr::CLASS_NAME => 'site',
		),
	)
)->render_open_tag();
// ──────── SKIP LINK ─────────────────────────────────────
do_action( Header_Hook::BEFORE_SKIP_LINK );
$html_builder->create_a(
	array(
		Html_Option::ATTRS => array(
			Html_Attr::CLASS_NAME => array(
				'skip-link',
				Accessibility_Class::SCREEN_READER_TEXT,
			),
			Html_Attr::HREF       => '#main',
		),
	)
)->render_element(
	esc_html__( 'Skip to content', 'errigal' )
);
// ──────── SITE HEADER ───────────────────────────────────
get_template_part( 'template-parts/header/site-header' );
// ──────── SITE CONTENT ──────────────────────────────────
$html_builder->create_div(
	array(
		Html_Option::ATTRS => array(
			Html_Attr::ID         => 'content',
			Html_Attr::CLASS_NAME => 'site-content',
		),
	)
)->render_open_tag();
// ────────── SITE CONTENT CONTAINER ──────────────────────
$html_builder->create_div(
	array(
		Html_Option::ATTRS => array(
			Html_Attr::CLASS_NAME => Component_Class::CONTAINER,
		),
	)
)->render_open_tag();
// ──────────── SITE CONTENT ROW ──────────────────────────
$html_builder->create_div(
	array(
		Html_Option::ATTRS => array(
			Html_Attr::CLASS_NAME => Component_Class::ROW,
		),
	)
)->render_open_tag();
// ────────────── CONTENT AREA ────────────────────────────
do_action( Content_Hook::BEFORE_CONTENT_AREA );
$html_builder->create_div(
	array(
		Html_Option::ATTRS => array(
			Html_Attr::ID         => 'primary',
			Html_Attr::CLASS_NAME => array(
				Content_Class::CONTENT_AREA,
				Component_Class::COL_12,
				Component_Class::COL_XL_8,
			),
		),
	)
)->render_open_tag();
// ──────────────── MAIN ──────────────────────────────────
$html_builder->create_main(
	array(
		Html_Option::ATTRS => array(
			Html_Attr::ID         => 'main',
			Html_Attr::CLASS_NAME => 'site-main',
			Html_Attr::ROLE       => 'main',
		),
	)
)->render_open_tag();
do_action( Header_Hook::BEFORE_MAIN_CONTENT );
