<?php if (get_theme_mod('archive_display', $default = true)) : ?>
	<?php
	$default_posts_per_page = get_option('posts_per_page');
	$archive_cat = get_theme_mod('archive_category');
	$paged = max(
		1,
		get_query_var('paged') ? get_query_var('paged') : 0,
		get_query_var('page') ? get_query_var('page') : 0
	);

	$args = array(
		'post_type'      => 'post',
		'posts_per_page' => absint($default_posts_per_page),
		'paged'          => $paged,
	);
	if (!empty($archive_cat)) {
		$args['cat'] = absint($archive_cat);
	}
	$wp_query = new WP_Query($args);
	?>

	<?php
	$layout = get_theme_mod('chic_lifestyle_archive_section_sidebar_layout', 'right-sidebar');
	$view = get_theme_mod('chic_lifestyle_post_view', 'list-view');

	$view_class = '';

	if ($view === 'grid-view') {
		$view_class = 'row row-cols-2 g-4';
	} elseif ($view === 'list-view') {
		$view_class = 'list-view';
	} else {
		$view_class = 'full-width-view';
	}


	$content_column_class = 'col-md-9';
	$sidebar_left_class = 'col-md-3';
	$sidebar_right_class = 'col-md-3';

	if ($layout == 'full-width' || $layout == 'no-sidebar') {
		$content_column_class = 'col-md-12';
	}

	$post_details = get_theme_mod('archive_list_details', array('date', 'categories', 'tags'));
	set_query_var('post_details', $post_details);

	if ($wp_query->have_posts()) { ?>
		<div id="chic_lifestyle_archive_sections" class="home-archive inside-page post-list py-48 px-0">
			<div class="container">
				<div class="row">
					<?php if ($layout == 'left-sidebar') { ?>
						<div class="<?php echo esc_attr($sidebar_left_class); ?>"><?php dynamic_sidebar('sidebar-1'); ?></div>
					<?php } ?>

					<div class="<?php echo esc_attr($content_column_class); ?>">
						<?php $archive_title = get_theme_mod('archive_title'); ?>
						<?php if (! empty($archive_title)) { ?><h2 class="news-heading mt-0 mb-8"><?php echo esc_html($archive_title); ?></h2><?php } ?>
						<div class="<?php echo esc_attr($view_class); ?> blog-list-block">

							<?php /* Start the Loop */ ?>
							<?php
							$post_index = 0;
							while ($wp_query->have_posts()) :
								$wp_query->the_post();
								$post_index++;

								$col_class = ($view === "grid-view") ? (($post_index === 1) ? 'col-12' : 'col-12 col-md-6') : "mb-12";
							?>
								<?php

								/** 
								 * Include the Post-Format-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 Format name) and that will be used instead.
								 */
								?>
								<div class="<?php echo $col_class; ?>">
									<?php get_template_part('template-parts/content', null, array(
										'view' => $view,
										'post_details' => $post_details,
										'section' => 'featured'
									));  ?>
								</div>
							<?php endwhile; ?>

							<?php wp_reset_postdata(); ?>
						</div>

						<?php
						global $wp_query;

						if ($wp_query->max_num_pages > 1) {
							if (get_theme_mod('chic_lifestyle_pagination_type', 'number-pagination') == 'number-pagination') {
								chic_lifestyle_numeric_pagination($wp_query);
							} else if (get_theme_mod('chic_lifestyle_pagination_type', 'number-pagination') == 'ajax-loadmore') { ?>
								<div id="chic_lifestyle_pagination" class="loadmore w-p100">
									<button view="<?php echo $view; ?>" class="d-block w-p100 border-0 p-12 bg-info bg-hover-primary text-white text-uppercase fw-semibold"><?php esc_html_e('More posts', 'chic-lifestyle'); ?></button>
								</div>
						<?php }
						}
						?>

					</div>

					<?php if ($layout == 'right-sidebar') { ?>
						<div class="<?php echo esc_attr($sidebar_right_class); ?>"><?php dynamic_sidebar('sidebar-1'); ?></div>
					<?php } ?>
				</div>
			</div>
		</div>


	<?php } ?>

<?php endif; ?>