<?php
/**
 * Project Type Taxonomy Archive Template
 *
 * @package KsPortfolio
 */

namespace KsPortfolio;

get_header();

$queried   = get_queried_object();
$term_name = $queried && ! is_wp_error( $queried ) ? $queried->name : __( 'Projects', 'ks-portfolio' );
?>
<section class="archive-projects">
	<div class="container mx-auto my-section">
		<header class="archive-projects__head">
			<h1 class="archive-projects__title"><?php echo esc_html( $term_name ); ?></h1>
			<p class="archive-projects__intro">
				<a class="archive-projects__back-link" href="<?php echo esc_url( get_post_type_archive_link( 'projects' ) ); ?>">
					<?php echo esc_html__( '&larr; All Projects', 'ks-portfolio' ); ?>
				</a>
			</p>
		</header>

		<?php if ( have_posts() ) : ?>
			<div class="archive-projects__grid grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
				<?php
				while ( have_posts() ) :
					the_post();
					get_template_part( 'views/components/project-card' );
				endwhile;
				?>
			</div>

			<div class="archive-projects__pagination">
				<?php
				the_posts_pagination(
					array(
						'mid_size'  => 2,
						'prev_text' => '&laquo; ' . esc_html__( 'Previous', 'ks-portfolio' ),
						'next_text' => esc_html__( 'Next', 'ks-portfolio' ) . ' &raquo;',
					)
				);
				?>
			</div>
		<?php else : ?>
			<div class="archive-projects__empty">
				<h2 class="archive-projects__empty-title"><?php echo esc_html__( 'Nothing here yet&hellip;', 'ks-portfolio' ); ?></h2>
				<p class="archive-projects__empty-desc"><?php echo esc_html__( 'No published projects found in this category.', 'ks-portfolio' ); ?></p>
			</div>
		<?php endif; ?>
	</div>
</section>

<?php
get_footer();
