<?php
/**
 * Author name.
 *
 * @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 Author
 */
final class Author implements CardPartInterface {

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

		$name = get_the_author_meta( 'display_name', (int) $ctx->post()->post_author );
		if ( '' === $name ) {
			return;
		}
		?>
		<span class="kutby-card__author"><?php echo esc_html( $name ); ?></span>
		<?php
	}
}
