<?php
/**
 * Template part for displaying posts in grid layout
 *
 * @subpackage storecraft
 * @since 1.0
 * @version 1.4
 */

$storecraft_categories = get_the_category();
$storecraft_category   = ( ! empty( $storecraft_categories ) && ! is_wp_error( $storecraft_categories ) ) ? $storecraft_categories[0]->name : '';
?>

<div class="col-lg-4 col-md-6 hbs-archive-grid-item">
	<article id="post-<?php the_ID(); ?>" <?php post_class( 'hbs-archive-card inner-service grid-layout' ); ?>>
		<div class="hbs-archive-card-image">
			<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
				<?php
				if ( has_post_thumbnail() ) {
					the_post_thumbnail( 'medium_large' );
				} else {
					echo '<img src="' . esc_url( get_template_directory_uri() . '/assets/images/default.png' ) . '" alt="' . esc_attr( get_the_title() ) . '" loading="lazy" />';
				}
				?>
			</a>
		</div>
		<div class="hbs-archive-card-body article_content">
			<div class="hbs-archive-meta metabox">
				<?php if ( ! empty( $storecraft_category ) ) : ?>
					<span class="hbs-archive-category"><?php echo esc_html( $storecraft_category ); ?></span>
				<?php endif; ?>
				<span class="hbs-archive-date entry-date">
					<svg width="14" height="14" viewBox="0 0 24 24" fill="none" aria-hidden="true" focusable="false">
						<rect x="3" y="5" width="18" height="16" rx="2" stroke="currentColor" stroke-width="1.8"/>
						<path d="M8 3v4M16 3v4M3 10h18" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/>
					</svg>
					<time datetime="<?php echo esc_attr( get_the_date( DATE_W3C ) ); ?>"><?php echo esc_html( get_the_date() ); ?></time>
				</span>
			</div>
			<h3 class="hbs-archive-title">
				<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
			</h3>
			<p class="hbs-archive-excerpt mb-0">
				<?php
				$storecraft_excerpt = get_the_excerpt();
				echo esc_html( storecraft_string_limit_words( $storecraft_excerpt, 18 ) );
				?>
			</p>
			<a href="<?php the_permalink(); ?>" class="hbs-archive-readmore read-btn">
				<?php esc_html_e( 'Read More', 'storecraft' ); ?> <span aria-hidden="true">&rarr;</span>
			</a>
		</div>
	</article>
</div>
