<?php
/**
 * Template part for displaying post header
 *
 * @package errigal
 * @since 1.0.0
 */

defined( 'ABSPATH' ) || exit;

use Errigal\Constant\{
	Errigal_Header_Class as Header_Class,
	Errigal_Header_Hook as Header_Hook,
	Errigal_Html_Attr as Html_Attr,
	Errigal_Html_Option as Html_Option,
};
use Errigal\Content\Errigal_Content as Content;
use Errigal\Header\Errigal_Header as Header;
use Errigal\Shared\Errigal_Html_Builder as Html_Builder;

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

		Content::render_post_thumbnail(
			'post-header__post-thumbnail',
			array(
				Content::THUMBNAIL_SHOULD_SHOW_BACKGROUND_IMAGE => false,
				Content::THUMBNAIL_SHOULD_INCLUDE_LINK => false,
			)
		);
		$html_builder->create_div(
			array(
				Html_Option::ATTRS => array(
					Html_Attr::CLASS_NAME => 'post-header__content',
				),
			)
		)->render_element(
			function ( $html_builder ) {
				if ( ! Html_Builder::is_html_builder( $html_builder ) ) {
					return;
				}

				get_template_part( 'template-parts/component/shared/categories' );
				$html_builder->create_h1(
					array(
						Html_Option::ATTRS => array(
							Html_Attr::CLASS_NAME => 'post-header__post-title',
						),
					)
				)->render_element(
					get_the_title()
				);
				get_template_part( 'template-parts/component/header/edit-post-link' );
				$html_builder->create_div(
					array(
						Html_Option::ATTRS => array(
							Html_Attr::CLASS_NAME => Header_Class::POST_HEADER_POST_METADATA,
						),
					)
				)->render_element(
					function () {
						get_template_part( 'template-parts/component/shared/posted-by' );
						get_template_part( 'template-parts/component/shared/posted-on' );
					}
				);
				do_action( Header_Hook::AFTER_POST_HEADER_CONTENT );
			}
		);
	}
);
