<?php
/**
 * Meta cluster (author, date, reading time).
 *
 * @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 Meta
 */
final class Meta implements CardPartInterface {

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

		ob_start();
		Author::render( $ctx );
		Date::render( $ctx );
		ReadingTime::render( $ctx );
		$inner = trim( (string) ob_get_clean() );

		if ( '' === $inner ) {
			return;
		}
		?>
		<div class="kutby-card__meta">
			<?php echo $inner; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- escaped in parts. ?>
		</div>
		<?php
	}
}
