<?php
/**
 * The template for displaying archive pages
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package    Wira
 * @since      1.0.0
 */

?>

<?php get_header(); ?>

<!-- Main Wrapper -->
<main id="main">

	<!-- Theme Wrapper -->
	<div class="wira-theme">

		<!-- Title Banner -->
		<?php get_template_part( 'template-parts/title-banner' ); ?>

		<!-- Main Section Wrapper -->
		<div class="container theme-section theme-space-wider">

			<!-- Row -->
			<div class="row gx-lg-5 gy-5">

				<!-- Columns Content -->
				<div class="col">

					<!-- Archive Count Label -->
					<?php if ( have_posts() ) : ?>
						<h4 class="mb-4">
							<?php
							if ( is_category() ) {
								$wira_archive_title = single_cat_title( '', false );
							} elseif ( is_tag() ) {
								$wira_archive_title = single_tag_title( '', false );
							} elseif ( is_author() ) {
								$wira_archive_title = get_the_author();
							} elseif ( is_year() ) {
								$wira_archive_title = get_the_date( 'Y' );
							} elseif ( is_month() ) {
								$wira_archive_title = get_the_date( 'F Y' );
							} elseif ( is_day() ) {
								$wira_archive_title = get_the_date( 'F j, Y' );
							} elseif ( is_post_type_archive() ) {
								$wira_archive_title = post_type_archive_title( '', false );
							} elseif ( is_tax() ) {
								$wira_archive_title = single_term_title( '', false );
							} else {
								$wira_archive_title = __( 'Archives', 'wira' );
							}
								$wira_total_results = $wp_query->found_posts;
								$wira_before_count  = get_theme_mod( 'wira_archive_before_count', __( 'Found', 'wira' ) );
								$wira_after_count   = get_theme_mod( 'wira_archive_after_count', __( 'post result on', 'wira' ) );

								echo wp_kses_post(
									sprintf(
										'%s <span class="theme-archive-count-label theme-color-primary">%d</span> %s "%s"',
										esc_html( $wira_before_count ),
										$wira_total_results,
										esc_html( $wira_after_count ),
										esc_html( $wira_archive_title )
									)
								);

							?>
						</h4>
					<?php endif; ?>

					<!-- Post Content Looping -->
					<div class="row row-cols-md-2 row-cols-1 gy-4 gx-lg-4">
						<?php
						if ( have_posts() ) :
							while ( have_posts() ) :
								the_post();
								get_template_part( 'template-parts/content/content' );
							endwhile;
						else :
							get_template_part( 'template-parts/content/content', 'none' );
						endif;
						?>
					</div>

					<!-- Paginations -->
					<?php
					if ( class_exists( 'Wira\Templates\Custom_Pagination' ) ) {
						$wira_pagination = new Wira\Templates\Custom_Pagination();
						$wira_pagination->render();
					}
					?>
				</div> <!-- Columns Content /End -->

				<!-- Sidebar Columns -->
				<?php get_sidebar(); ?>
			</div> <!-- Row /End -->
		</div> <!-- Main Section Wrapper /End -->
	</div> <!-- Theme Wrapper /End -->
</main> <!-- Main Wrapper /End -->

<?php get_footer(); ?>
