<?php
/**
 * The template for displaying archive pages
 *
 * @package Rosea
 *
 * This file is part of the Rosea WordPress theme.
 *
 * Rosea WordPress Theme, Copyright 2026 nopStation
 * Rosea is distributed under the terms of the GNU General Public License v2 or later.
 *
 * @license GPL-2.0-or-later
 * @license URI: https://www.gnu.org/licenses/gpl-2.0.html
 */

get_header();
?>

<main id="main" role="main">
<!--blog main content-->
<div class="blog-page-container">
	<h1 class="blog-title"><?php the_archive_title(); ?></h1>
	
	<div class="blog-content-wrapper">
		<?php get_sidebar(); ?>
		
		<!-- Blog Posts -->
		<div class="blog-posts">
			<?php
			if ( have_posts() ) :
				while ( have_posts() ) :
					the_post();
					?>
					<article class="blog-post">
						<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
					<div class="post-content">
						<?php the_excerpt(); ?>
					</div>
					<div class="post-meta">
						<span class="post-date">
							<i class="far fa-calendar"></i> <?php echo esc_html( get_the_date() ); ?>
						</span>
						<span class="post-author">
							<i class="far fa-user"></i> <a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>"><?php echo esc_html( get_the_author() ); ?></a>
						</span>
						<?php
						$categories = get_the_category();
						if ( ! empty( $categories ) ) {
							?>
							<span class="post-category">
								<i class="far fa-folder"></i> <a href="<?php echo esc_url( get_category_link( $categories[0]->term_id ) ); ?>"><?php echo esc_html( $categories[0]->name ); ?></a>
							</span>
							<?php
						}
						?>
						<a href="<?php comments_link(); ?>"><?php comments_number( 'Comments (0)', 'Comments (1)', 'Comments (%)' ); ?></a>
						<a href="<?php the_permalink(); ?>"><?php esc_html_e( 'Details', 'rosea' ); ?></a>
						</div>
						<?php
						$tags = get_the_tags();
						if ( $tags ) {
							?>
							<div class="post-tags">
								Tags: 
								<?php
								$tag_links = array();
								foreach ( $tags as $tag ) {
									$tag_links[] = '<a href="' . esc_url( get_tag_link( $tag->term_id ) ) . '">' . esc_html( $tag->name ) . '</a>';
								}
								echo implode( ', ', $tag_links ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
								?>
							</div>
							<?php
						}
						?>
					</article>
					<?php
				endwhile;
				?>
				
				<!-- Pagination -->
				<div class="blog-pagination">
					<?php
					the_posts_pagination( array(
						'mid_size'  => 2,
						'prev_text' => __( '&laquo; Previous', 'rosea' ),
						'next_text' => __( 'Next &raquo;', 'rosea' ),
					) );
					?>
				</div>
				<?php
			else :
				?>
				<div class="no-posts-found">
					<p><?php esc_html_e( 'No posts found.', 'rosea' ); ?></p>
				</div>
				<?php
			endif;
			?>
		</div>
	</div>
</div>
<!--blog main content-->
</main>

<?php
get_footer();
