<?php
/**
 * Template part for displaying a post card in loops.
 *
 * @package nxt-event-planner
 */

$nxt_event_planner_bg_image_url = '';
$nxt_event_planner_extra_class  = '';

if ( has_post_thumbnail() ) {
    $nxt_event_planner_bg_image_url = get_the_post_thumbnail_url( null, 'large' );
} else {
    $nxt_event_planner_extra_class = nxt_event_planner_get_random_gradient_class();
}
?>

<article id="post-<?php the_ID(); ?>" <?php post_class( 'post-card' ); ?>>
    <div class="post-card-image-wrapper">
        <a href="<?php the_permalink(); ?>" class="post-card-image <?php echo esc_attr( $nxt_event_planner_extra_class ); ?>"<?php if ( $nxt_event_planner_bg_image_url ) : ?> style="background-image: url(<?php echo esc_url( $nxt_event_planner_bg_image_url ); ?>);"<?php endif; ?>></a>

        <div class="post-card-meta-top">
            <div class="meta-left">
                <span class="meta-item meta-date"><?php echo esc_html( get_the_date( 'M d, Y' ) ); ?></span>
            </div>
            <div class="meta-right">
                <span class="meta-item meta-comments"><?php comments_popup_link( esc_html__( 'No comments', 'nxt-event-planner' ), esc_html__( '1 comment', 'nxt-event-planner' ), esc_html__( '% comments', 'nxt-event-planner' ) ); ?></span>
            </div>
        </div>
    </div>

    <div class="post-card-content">
        <h2 class="post-card-title">
            <a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a>
        </h2>

        <div class="post-card-excerpt">
            <?php the_excerpt(); ?>
        </div>

        <div class="post-card-footer">
            <a class="post-card-more" href="<?php the_permalink(); ?>"><?php esc_html_e( 'Read article', 'nxt-event-planner' ); ?></a>
        </div>
    </div>
</article>
