<?php
/**
 * The main template file
 * @package Local Supermarket
 * @since 1.0.0
 */

get_header();

$local_supermarket_layout = local_supermarket_get_final_sidebar_layout();
$local_supermarket_column_class = ($local_supermarket_layout === 'right-sidebar') ? 'column-order-1' : 'column-order-2'; ?>

    <div class="header-image-box text-center">
        <div class="header-image-box-inner">

            <?php
            if ( is_search() ) {
                echo '<h1 class="mb-0">';
                printf(
                    esc_html__( 'Search Results for: %s', 'local-supermarket' ),
                    '<span>' . esc_html( get_search_query() ) . '</span>'
                );
                echo '</h1>';
            } else {
                the_archive_title('<h1 class="mb-0">', '</h1>');
                the_archive_description();
            }
            ?>

        </div>
    </div>

    <!-- Elementor Active → Show Main Theme Layout -->
    <div class="archive-main-block">
        <div class="wrapper">
            <div class="column-row <?php echo esc_attr($local_supermarket_layout === 'no-sidebar' ? 'no-sidebar-layout' : ''); ?>">

                <div id="primary" class="content-area <?php echo esc_attr($local_supermarket_column_class); ?>">
                    <main role="main">

                        <?php
                        if ( !is_front_page() ) {
                            local_supermarket_breadcrumb();
                        }

                        if ( have_posts() ) : ?>

                            <div class="article-wraper article-wraper-archive">
                                <?php
                                while ( have_posts() ) :
                                    the_post();
                                    get_template_part('template-parts/content', get_post_format());
                                endwhile;
                                ?>
                            </div>

                            <?php
                            if ( is_search() ) {
                                the_posts_pagination();
                            } else {
                                do_action('local_supermarket_posts_pagination');
                            }

                        else :
                            get_template_part('template-parts/content', 'none');
                        endif;
                        ?>
                    </main>
                </div>

                <?php if ( $local_supermarket_layout !== 'no-sidebar' ) get_sidebar(); ?>

            </div>
        </div>
    </div>

<?php get_footer(); ?>
