<?php
/**
 * The sidebar template file
 *
 * Displays the sidebar widget area with archive and tags.
 *
 * @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
 */
?>

<aside class="blog-sidebar">
	<?php if ( is_active_sidebar( 'sidebar-1' ) ) : ?>
		<?php dynamic_sidebar( 'sidebar-1' ); ?>
	<?php else : ?>
		<!-- Blog Archive -->
		<div class="sidebar-section">
			<h4 class="sidebar-title"><?php esc_html_e( 'BLOG ARCHIVE', 'rosea' ); ?></h4>
			<ul class="sidebar-list">
				<?php
				wp_get_archives( array(
					'type'  => 'monthly',
					'limit' => 12,
					'format' => 'html',
					'before' => '<li><a href="%url"><span class="sidebar-arrow">►</span> ',
					'after'  => '</a></li>',
				) );
				?>
			</ul>
		</div>
		
		<!-- Popular Blog Tags -->
		<div class="sidebar-section">
			<h4 class="sidebar-title"><?php esc_html_e( 'POPULAR BLOG TAGS', 'rosea' ); ?></h4>
			<ul class="sidebar-list">
				<?php
				$tags = get_tags( array( 'orderby' => 'count', 'order' => 'DESC', 'number' => 10 ) );
				if ( $tags ) {
					foreach ( $tags as $tag ) {
						echo '<li><a href="' . esc_url( get_tag_link( $tag->term_id ) ) . '"><span class="sidebar-arrow">►</span> ' . esc_html( strtoupper( $tag->name ) ) . '</a></li>';
					}
				}
				?>
			</ul>
		</div>
	<?php endif; ?>
</aside>
