<?php

/**
 * The sidebar containing the main widget area
 *
 * @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
 *
 * @package bakery_confectionery
 */
?>

<aside id="secondary" class="widget-area wow zoomIn delay-1000" data-wow-duration="2s">
	<?php dynamic_sidebar( 'sidebar-1' ); ?>
</aside><!-- #secondary -->

<?php 
  if ( ! is_active_sidebar( 'sidebar-1' )) { ?>
	<aside id="secondary" class="widget-area wow zoomIn delay-1000" data-wow-duration="2s">
		<section id="Search" class="widget widget_block widget_archive">
		    <h2 class="widget-title"><?php esc_html_e('Search', 'bakery-confectionery'); ?></h2>
		    <?php get_search_form(); ?>
		</section>
		<section id="archives" class="widget widget_block widget_archive">
		    <h2 class="widget-title"><?php esc_html_e('Archives', 'bakery-confectionery'); ?></h2>
		    <ul>
		        <?php
		        wp_get_archives(array(
		            'type'            => 'monthly',
		            'show_post_count' => true,
		        ));
		        ?>
		    </ul>
		</section>
		<section id="categories" class="widget widget_categories" role="complementary">
		    <h2 class="widget-title"><?php esc_html_e('Categories', 'bakery-confectionery'); ?></h2>
		    <ul>
		        <?php
		        wp_list_categories(array(
		            'orderby'    => 'name',
		            'title_li'   => '',
		            'show_count' => true,
		        ));
		        ?>
		    </ul>
		</section>
		<section id="tags" class="widget widget_tag_cloud" role="complementary">
		    <h2 class="widget-title"><?php esc_html_e('Tags', 'bakery-confectionery'); ?></h2>
		    <?php
				$bakery_confectionery_tags = get_tags();
				if ($bakery_confectionery_tags) {
				    echo '<div class="tag-cloud">';
				    foreach ($bakery_confectionery_tags as $bakery_confectionery_tag) {
				        $bakery_confectionery_tag_link = get_tag_link($bakery_confectionery_tag->term_id);
				        echo '<a href="' . esc_url($bakery_confectionery_tag_link) . '" style="font-size:' . esc_attr($bakery_confectionery_tag->font_size) . 'px;" class="tag-link">' . esc_html($bakery_confectionery_tag->name) . '</a>';
				    }
				    echo '</div>';
				} else {
				    echo '<p>No tags found.</p>';
				}
			?>
		</section>
		<section id="recent-posts" class="widget" role="complementary">
		    <h2 class="widget-title"><?php esc_html_e('Recent Posts', 'bakery-confectionery'); ?></h2>
		    <ul class="recent-posts-list">
		        <?php
		        $bakery_confectionery_recent_posts = get_posts(array(
		            'numberposts' => 5, // Adjust the number of posts to display
		            'post_status' => 'publish',
		        ));

		        foreach ($bakery_confectionery_recent_posts as $bakery_confectionery_post) :
		            setup_postdata($bakery_confectionery_post);
		            ?>
		            <li>
		                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
		            </li>
		            <?php
		        endforeach;
		        wp_reset_postdata();
		        ?>
		    </ul>
		</section>
	</aside>
<?php } ?>