<?php
/**
 * Template part for displaying post created/modified date
 *
 * @package errigal
 * @since 1.0.0
 */

defined( 'ABSPATH' ) || exit;

use Errigal\Constant\{
	Errigal_Html_Attr as Html_Attr,
	Errigal_Html_Option as Html_Option,
};
use Errigal\Content\Errigal_Content as Content;
use Errigal\Shared\Errigal_Html_Builder as Html_Builder;

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

		$is_modified = Content::is_modified();

		$html_builder->create_span()->render_element(
			esc_html(
				$is_modified
					? __( 'Updated ', 'errigal' )
					: __( 'Published ', 'errigal' )
			)
		);
		$html_builder->create_time(
			array(
				Html_Option::ATTRS => array(
					Html_Attr::CLASS_NAME => array(
						'entry-date',
						$is_modified
							? 'updated'
							: 'published',
					),
					Html_Attr::DATETIME   => $is_modified
						? get_the_modified_date( DATE_W3C )
						: get_the_date( DATE_W3C ),
				),
			)
		)->render_element(
			esc_html(
				$is_modified
					? get_the_modified_date()
					: get_the_date()
			)
		);
	}
);
