<?php
/**
 * Compact article card.
 *
 * @package Kutby
 * @since   2.8.0
 */

declare(strict_types=1);

namespace Kutby\Hero\Components;

use Kutby\Hero\Contracts\HeroComponentInterface;
use Kutby\Hero\Support\HeroContext;
use WP_Post;

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

/**
 * Class ArticleCard
 */
final class ArticleCard implements HeroComponentInterface {

	/**
	 * {@inheritdoc}
	 */
	public static function render( HeroContext $ctx, array $args = array() ): void {
		$post = $args['post'] ?? null;
		if ( ! $post instanceof WP_Post ) {
			Skeleton::render( $ctx );
			return;
		}

		$class = isset( $args['class'] ) ? (string) $args['class'] : 'kutby-hero-card';
		?>
		<article <?php post_class( $class, $post ); ?>>
			<a class="kutby-hero-card__media-link" href="<?php echo esc_url( get_permalink( $post ) ); ?>">
				<?php
				BackgroundImage::render(
					$ctx,
					array(
						'post'  => $post,
						'lazy'  => true,
						'size'  => 'medium_large',
						'class' => 'kutby-hero-media kutby-hero-media--card',
					)
				);
				?>
			</a>
			<div class="kutby-hero-card__body">
				<?php CategoryBadge::render( $ctx, array( 'post' => $post ) ); ?>
				<h3 class="kutby-hero-card__title">
					<a href="<?php echo esc_url( get_permalink( $post ) ); ?>"><?php echo esc_html( get_the_title( $post ) ); ?></a>
				</h3>
				<?php ArticleMeta::render( $ctx, array( 'post' => $post ) ); ?>
			</div>
		</article>
		<?php
	}
}
