<?php
/**
 * Publish date.
 *
 * @package Kutby
 * @since   2.9.0
 */

declare(strict_types=1);

namespace Kutby\Cards\Parts;

use Kutby\Cards\Contracts\CardPartInterface;
use Kutby\Cards\Support\CardContext;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Class Date
 */
final class Date implements CardPartInterface {

	/**
	 * {@inheritdoc}
	 */
	public static function render( CardContext $ctx, array $args = array() ): void {
		if ( ! $ctx->bool( 'show_date' ) ) {
			return;
		}

		$post = $ctx->post();
		?>
		<time class="kutby-card__date" datetime="<?php echo esc_attr( get_the_date( DATE_W3C, $post ) ); ?>">
			<?php echo esc_html( get_the_date( '', $post ) ); ?>
		</time>
		<?php
	}
}
