<?php
/**
 * The template for displaying archive pages
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package Blog Bee
 */
use BBE\Helpers as Helpers;
use BBE\Query_Manager as Query_Manager;
use BBE\Customizer\Theme_Defaults as Theme_Defaults;
use BBE\Customizer\Section\Pagination as Pagination;
use BBE\Customizer\Section\Archives as Archives;
use BBE\Customizer\Section\Advertisement as Advertisement;
use BBE\Customizer\Section\You_May_Have_Missed as You_May_Have_Missed;

$archives = Archives::get_instance();
$archives->check_layout_post_meta();
$masonry = $archives->get_masonry();
$layout = $archives->get_layout();

get_header();

	echo '<div class="bbe-sections-wrap">';

		Query_Manager::get_archive_opener();

			?>

				<header class="page-header">
					<?php
						the_archive_title( '<h1 class="page-title">', '</h1>' );
						Helpers::the_archive_count();
						the_archive_description( '<div class="archive-description">', '</div>' );
					?>
				</header><!-- .page-header -->

				<?php ob_start(); ?>

					<main id="primary" class="site-main" <?php Helpers::the_aos_data_attr(); ?>>

						<?php
							if ( have_posts() ) :

								echo '<div class="article-wrap">';

									if( ( $layout !== 'list' ) && $masonry ) echo '<div class="bbe-masonry-sizer"></div>';

									Advertisement::get_instance()->prepare_random_ads();

									/* Start the Loop */
									while ( have_posts() ) :
										the_post();

										Advertisement::get_instance()->get_random_advertisement();

										/*
										* Include the Post-Type-specific template for the content.
										* If you want to override this in a child theme, then include a file
										* called content-___.php (where ___ is the Post Type name) and that will be used instead.
										*/
										get_template_part( 'template-parts/content', get_post_type() );

									endwhile;

								echo '</div><!-- .article-wrap -->';
									
								Pagination::get_instance()->render_html();

							else :

								get_template_part( 'template-parts/content', 'none' );

							endif;
						?>

					</main><!-- #primary -->

				<?php
					$content = ob_get_clean();

					$content_args = [
						'content'	=>	$content
					];

					get_template_part( 'template-parts/content', 'sidebar-reorder', $content_args );
				?>

			<?php

		Query_Manager::get_archive_closer();

		You_May_Have_Missed::get_instance()->render_html();

	echo '</div><!-- .bbe-sections-wrap -->';

get_footer();
