<?php
$page_layout = is_author() ? glamer_options('glamer_authors_layout') : 
    (is_archive() ? glamer_options('glamer_archive_layout') : 
    (is_search() ? glamer_options('glamer_search_layout') : glamer_options('glamer_blog_layout')));

// Determine post grid style based on the context (archive, author, search, or blog)
$post_grid_style = is_author() ? glamer_options('glamer_author_grid_style', 'one') : 
    (is_archive() ? glamer_options('glamer_archive_grid_style', 'one') : 
    (is_search() ? glamer_options('glamer_search_grid_style', 'one') : glamer_options('glamer_blog_grid_style', 'one')));

$blog_layout_overwrite = $_GET['bs'] ?? $page_layout;
$post_grid_style_overwrite = $_GET['style'] ?? $post_grid_style;

$page_column_class = (in_array($blog_layout_overwrite, ['grid-ls', 'grid-rs']) && is_active_sidebar('sidebar')) 
    ? 'col-lg-12 col-xl-8'
    : 'col-lg-12';
?>
<div class="row content-<?php echo esc_attr($blog_layout_overwrite); ?>">
	<?php if (in_array($blog_layout_overwrite, ['grid-ls']) && is_active_sidebar('sidebar')): ?>
        <?php get_sidebar(); ?>
    <?php endif; ?>
	<div class="<?php echo esc_attr($page_column_class); ?>">
		<div class="row all-posts-wrapper grid-masonary">
			<?php
			if (have_posts()) :
				if (is_home() && ! is_front_page()) :
			?>
			<header>
				<h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
			</header>
			<?php
				endif;
				/* Start the Loop */
				while (have_posts()) :
					the_post();
					get_template_part('template-parts/post/post-grid/grid-style-'.$post_grid_style_overwrite.'');
				endwhile;
			else :
				get_template_part('template-parts/content', 'none');
			endif;
			?>
		</div>
		<?php
		$show_pagination = glamer_options('glamer_show_pagination', true);
		if ($show_pagination == true) {
			get_template_part('template-parts/post/post-pagination');
		}
		?>
	</div>
	<?php if (in_array($blog_layout_overwrite, ['grid-rs']) && is_active_sidebar('sidebar')): ?>
        <?php get_sidebar(); ?>
    <?php endif; ?>
</div>