<?php
get_header();
?>

<main id="primary" class="site-main" role="main">
	<section class="blog-archive-section">
		<div class="container">

			<?php if ( ! function_exists( 'vista_show' ) || vista_show( 'show_breadcrumb', true ) ) { vista_breadcrumbs(); } ?>

			<div class="blog-archive-header">
				<div>
					<h1 class="section-title">
						<?php
						printf(
							esc_html__( 'نتایج برای: %s', 'vista' ),
							'<span style="color:var(--p);">' . esc_html( get_search_query() ) . '</span>'
						);
						?>
					</h1>
				</div>
				<div style="font-size:13px;color:var(--t3);">
					<?php
					global $wp_query;
					printf(
						esc_html( _n( '%d نتیجه یافت شد', '%d نتیجه یافت شد', $wp_query->found_posts, 'vista' ) ),
						(int) $wp_query->found_posts
					);
					?>
				</div>
			</div>

			<?php if ( have_posts() ) : ?>
				<div class="blog-grid">
					<?php
					$count = 0;
					while ( have_posts() ) :
						the_post();
						$count++;
						$delay = 'd' . min( $count, 4 );
						?>
						<article id="post-<?php the_ID(); ?>" <?php post_class( 'blog-card rv ' . $delay ); ?>>

							<div class="blog-card-thumb">
								<?php if ( has_post_thumbnail() ) : ?>
									<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( 'vista-blog-card', array( 'loading' => 'lazy' ) ); ?></a>
								<?php else : ?>
									<a href="<?php the_permalink(); ?>">
										<i class="fa-solid fa-magnifying-glass" style="font-size:32px;color:var(--t3);" aria-hidden="true"></i>
									</a>
								<?php endif; ?>

								<?php $cats = get_the_category(); if ( $cats ) : ?>
									<a href="<?php echo esc_url( get_category_link( $cats[0]->term_id ) ); ?>" class="blog-card-cat">
										<?php echo esc_html( $cats[0]->name ); ?>
									</a>
								<?php endif; ?>
							</div>

							<div class="blog-card-body">
								<div class="blog-card-meta">
									<time datetime="<?php echo esc_attr( get_the_date( 'c' ) ); ?>"><?php echo esc_html( get_the_date() ); ?></time>
									<span class="blog-card-meta-sep"></span>
									<span><?php the_author(); ?></span>
								</div>
								<h2 class="blog-card-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
								<div class="blog-card-excerpt"><?php the_excerpt(); ?></div>
								<div class="blog-card-footer">
									<a href="<?php the_permalink(); ?>" class="blog-card-more">
										<?php esc_html_e( 'ادامه مطلب', 'vista' ); ?>
										<i class="fa-solid fa-arrow-<?php echo is_rtl() ? esc_attr('left') : esc_attr('right'); ?>"></i>
									</a>
									<?php vista_reading_time( get_the_ID() ); ?>
								</div>
							</div>

						</article>
					<?php endwhile; ?>
				</div>

				<div class="pagination-wrap">
					<?php
					echo wp_kses_post( paginate_links( array(
						'type'      => 'list',
						'prev_text' => is_rtl() ? '<i class="fa-solid fa-chevron-right"></i>' : '<i class="fa-solid fa-chevron-left"></i>',
						'next_text' => is_rtl() ? '<i class="fa-solid fa-chevron-left"></i>' : '<i class="fa-solid fa-chevron-right"></i>',
					) ) );
					?>
				</div>

			<?php else : ?>
				<div style="text-align:center;padding:60px 20px;">
					<i class="fa-solid fa-face-sad-tear" style="font-size:48px;color:var(--t3);margin-bottom:16px;display:block;"></i>
					<h2 style="font-size:20px;font-weight:800;color:var(--t1);margin-bottom:10px;">
						<?php esc_html_e( 'نتیجه‌ای یافت نشد', 'vista' ); ?>
					</h2>
					<p style="font-size:14px;color:var(--t2);">
						<?php esc_html_e( 'عبارت دیگری را امتحان کنید.', 'vista' ); ?>
					</p>
				</div>
			<?php endif; ?>

		</div>
	</section>
</main>

<?php get_footer();
