<?php
/** Compact editorial news card. @package Gustavo_Portfolio */

$gustavoo_args        = isset( $args ) && is_array( $args ) ? $args : array();
$gustavoo_is_featured = ! empty( $gustavoo_args['featured'] );
$gustavoo_categories  = get_the_category();
$gustavoo_category    = $gustavoo_categories ? $gustavoo_categories[0] : null;
$gustavoo_image_url   = gustavoo_portfolio_get_news_image_url( get_the_ID(), $gustavoo_is_featured ? 'large' : 'gustavoo-post-card' );
?>
<article <?php post_class( 'latest-news-card' . ( $gustavoo_is_featured ? ' latest-news-card--featured' : '' ) ); ?>>
	<a class="latest-news-card__media" href="<?php the_permalink(); ?>" aria-hidden="true" tabindex="-1">
		<?php if ( $gustavoo_image_url ) : ?>
			<img class="latest-news-card__image" src="<?php echo esc_url( $gustavoo_image_url ); ?>" loading="<?php echo $gustavoo_is_featured ? 'eager' : 'lazy'; ?>" decoding="async" alt="">
		<?php else : ?><span class="latest-news-card__placeholder" aria-hidden="true"></span><?php endif; ?>
	</a>
	<div class="latest-news-card__body">
		<?php if ( $gustavoo_category ) : ?><a class="latest-news-card__category" href="<?php echo esc_url( get_category_link( $gustavoo_category ) ); ?>"><?php echo esc_html( $gustavoo_category->name ); ?></a><?php endif; ?>
		<h2 class="latest-news-card__title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
		<time class="latest-news-card__date" datetime="<?php echo esc_attr( get_the_date( DATE_W3C ) ); ?>"><?php echo esc_html( get_the_date() ); ?></time>
		<?php if ( $gustavoo_is_featured && has_excerpt() ) : ?><p class="latest-news-card__excerpt"><?php echo esc_html( wp_trim_words( get_the_excerpt(), 28 ) ); ?></p><?php endif; ?>
	</div>
</article>
