<?php
/**
 * Professional posts archive at /blog.
 *
 * @package Shabnam_MuchWOW
 */
defined( 'ABSPATH' ) || exit;
get_header();

$shabnam_label      = function_exists( 'shabnam_get_setting' ) ? shabnam_get_setting( 'blog_archive_label', 'مجله' ) : 'مجله';
$shabnam_title      = function_exists( 'shabnam_get_setting' ) ? shabnam_get_setting( 'blog_archive_title', 'تازه‌ترین نوشته‌ها' ) : 'تازه‌ترین نوشته‌ها';
$shabnam_columns    = function_exists( 'shabnam_blog_columns' ) ? shabnam_blog_columns() : 3;
$shabnam_post_count = wp_count_posts( 'post' );
$shabnam_published  = isset( $shabnam_post_count->publish ) ? absint( $shabnam_post_count->publish ) : 0;
$shabnam_categories = get_categories(
	array(
		'hide_empty' => true,
		'number'     => 6,
		'orderby'    => 'count',
		'order'      => 'DESC',
	)
);
?>
<main id="primary" class="shabnam-blog-archive shabnam-inner-page section panel overflow-hidden">
	<div class="section-outer panel py-8 lg:py-10">
		<div class="container sm:max-w-md xl:max-w-lg">
			<header class="shabnam-blog-archive-hero panel text-center" data-anime="onview: -200; targets: >*; translateY: [20, 0]; opacity: [0, 1]; delay: anime.stagger(80, {start: 80});">
				<div class="category"><div class="-rotate-2"><span class="fs-5 xl:fs-4 text-secondary fw-bold"><?php echo esc_html( $shabnam_label ); ?></span></div></div>
				<h1 class="h3 sm:h2 xl:display-6 mb-0 mt-2 text-white"><?php echo esc_html( $shabnam_title ); ?></h1>
				<p class="shabnam-blog-archive-lead"><?php esc_html_e( 'مقاله‌ها، آموزش‌ها و تازه‌ترین مطالب را یک‌جا دنبال کنید.', 'shabnam-muchwow' ); ?></p>
				<div class="shabnam-blog-archive-tools">
					<form class="shabnam-blog-search" role="search" method="get" action="<?php echo esc_url( home_url( '/' ) ); ?>">
						<label class="screen-reader-text" for="shabnam-blog-search-input"><?php esc_html_e( 'جست‌وجوی نوشته‌ها', 'shabnam-muchwow' ); ?></label>
						<input id="shabnam-blog-search-input" type="search" name="s" value="<?php echo esc_attr( get_search_query() ); ?>" placeholder="<?php esc_attr_e( 'در نوشته‌ها جست‌وجو کنید…', 'shabnam-muchwow' ); ?>">
						<input type="hidden" name="post_type" value="post">
						<button type="submit"><?php esc_html_e( 'جست‌وجو', 'shabnam-muchwow' ); ?></button>
					</form>
					<span class="shabnam-blog-count"><?php echo esc_html( sprintf( _n( '%d نوشته منتشرشده', '%d نوشته منتشرشده', $shabnam_published, 'shabnam-muchwow' ), $shabnam_published ) ); ?></span>
				</div>
				<?php if ( $shabnam_categories ) : ?>
					<nav class="shabnam-blog-categories" aria-label="<?php esc_attr_e( 'دسته‌بندی‌های وبلاگ', 'shabnam-muchwow' ); ?>">
						<?php foreach ( $shabnam_categories as $shabnam_category ) : ?>
							<a href="<?php echo esc_url( get_category_link( $shabnam_category ) ); ?>"><?php echo esc_html( $shabnam_category->name ); ?><small><?php echo esc_html( number_format_i18n( $shabnam_category->count ) ); ?></small></a>
						<?php endforeach; ?>
					</nav>
				<?php endif; ?>
			</header>

			<?php if ( have_posts() ) : ?>
				<div class="shabnam-blog-grid" style="--shcd-blog-columns:<?php echo esc_attr( $shabnam_columns ); ?>">
					<?php while ( have_posts() ) : the_post(); ?>
						<?php get_template_part( 'template-parts/content', 'card' ); ?>
					<?php endwhile; ?>
				</div>
				<nav class="shabnam-pagination mt-6" aria-label="<?php esc_attr_e( 'صفحه‌بندی نوشته‌ها', 'shabnam-muchwow' ); ?>"><?php the_posts_pagination( array( 'mid_size' => 2, 'prev_text' => '→', 'next_text' => '←' ) ); ?></nav>
			<?php else : ?>
				<div class="shabnam-section-card panel p-5 border border-1 border-gray-100 border-opacity-40 rounded-3 text-center"><p class="m-0"><?php esc_html_e( 'هنوز نوشته‌ای منتشر نشده است.', 'shabnam-muchwow' ); ?></p></div>
			<?php endif; ?>
		</div>
	</div>
</main>
<?php get_footer(); ?>
