<?php
$sneakers_sports_shoes_layout = sneakers_sports_shoes_get_final_sidebar_layout();
$sneakers_sports_shoes_sidebar_class = 'column-order-1';

if ( $sneakers_sports_shoes_layout === 'left-sidebar' ) {
    $sneakers_sports_shoes_sidebar_class = 'column-order-1';
} elseif ( $sneakers_sports_shoes_layout === 'right-sidebar' ) {
    $sneakers_sports_shoes_sidebar_class = 'column-order-2';
}

if ( $sneakers_sports_shoes_layout !== 'no-sidebar' ) : ?>
    <aside id="secondary" class="widget-area <?php echo esc_attr( $sneakers_sports_shoes_sidebar_class ); ?>">
        <div class="widget-area-wrapper">
            <?php if ( is_active_sidebar('sidebar-1') ) : ?>
                <?php dynamic_sidebar( 'sidebar-1' ); ?>
            <?php else : ?>
                <!-- Default widgets -->
                <div class="widget widget_block widget_search">
                    <h3 class="widget-title"><?php esc_html_e('Search', 'sneakers-sports-shoes'); ?></h3>
                    <?php get_search_form(); ?>
                </div>

                <div class="widget widget_pages">
                    <h3 class="widget-title"><?php esc_html_e('Pages', 'sneakers-sports-shoes'); ?></h3>
                    <ul>
                        <?php
                        wp_list_pages(array(
                            'title_li' => '',
                        ));
                        ?>
                    </ul>
                </div>

                <div class="widget widget_archive">
                    <h3 class="widget-title"><?php esc_html_e('Archives', 'sneakers-sports-shoes'); ?></h3>
                    <ul>
                        <?php wp_get_archives(['type' => 'monthly', 'show_post_count' => true]); ?>
                    </ul>
                </div>

                <div class="widget widget_categories">
                    <h3 class="widget-title"><?php esc_html_e('Categories', 'sneakers-sports-shoes'); ?></h3>
                    <ul class="wp-block-categories-list wp-block-categories">
                        <?php wp_list_categories(['orderby' => 'name', 'title_li' => '', 'show_count' => true]); ?>
                    </ul>
                </div>

                <div class="widget widget_tag_cloud">
                    <h3 class="widget-title"><?php esc_html_e('Tags', 'sneakers-sports-shoes'); ?></h3>
                    <?php
                    $sneakers_sports_shoes_tags = get_tags();
                    if ( $sneakers_sports_shoes_tags ) {
                        echo '<div class="tagcloud">';
                        foreach ( $sneakers_sports_shoes_tags as $sneakers_sports_shoes_tag ) {
                            $sneakers_sports_shoes_link = get_tag_link($sneakers_sports_shoes_tag->term_id);
                            echo '<a href="' . esc_url($sneakers_sports_shoes_link) . '" class="tag-cloud-link">' . esc_html($sneakers_sports_shoes_tag->name) . '</a> ';
                        }
                        echo '</div>';
                    } else {
                        echo '<p>' . esc_html__('No tags found.', 'sneakers-sports-shoes') . '</p>';
                    }
                    ?>
                </div>

            <?php endif; ?>
        </div>
    </aside>
<?php endif; ?>
