<?php
/**
 * The template for displaying archive pages.
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 * @package Chic Lifestyle
 */

get_header(); ?>

<?php
  $view = get_theme_mod( 'chic_lifestyle_blog_view', 'list-view' );
  $layout = get_theme_mod('chic_lifestyle_blog_layout', 'right-sidebar');
  $width_class = 'col-12 col-lg-8';
  if( $layout == 'no-sidebar' ) {
    $width_class = 'col-12';
  }

  $post_details = get_theme_mod( 'chic_lifestyle_post_details', array( 'date', 'categories', 'tags' ) );
  set_query_var( 'post_details', $post_details );
?>

<div class="post-list py-5">
  <div class="container">
    <?php if( have_posts() ) :
      the_archive_title( '<h1 class="my-32">', '</h1>' );
      the_archive_description( '<p class="mb-5">', '</p>' );
    endif; ?>

    <div class="row g-4">
      <?php if( $layout == 'left-sidebar' ) : ?>
        <div class="col-12 col-lg-4"><?php dynamic_sidebar('sidebar-1'); ?></div>
      <?php endif; ?>
      
      <div class="<?php echo esc_attr( $width_class ); ?>">
        <div class="<?php echo esc_attr($view); ?> row row-gap-12 row-gap-sm-20 blog-list-block">
          <?php if ( have_posts() ) : ?>
            <?php while ( have_posts() ) : the_post(); ?>
              <?php 
                get_template_part( 'template-parts/content' ,null, array(
                  'view' => $view,
                  'post_details' => $post_details
                ) );
              ?>
            <?php endwhile; ?>
          <?php else : ?>
            <?php 
              get_template_part( 'template-parts/content', null, array(
                'view' => $view,
                'post_details' => $post_details
              ) );
            ?>
          <?php endif; ?>
        </div>
      </div>
    
      <?php if( $layout == 'right-sidebar' ) : ?>
        <div class="col-12 col-lg-4"><?php dynamic_sidebar('sidebar-1'); ?></div>
      <?php endif; ?>
    </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 text-bg-info text-white text-uppercase fw-semibold bg-hover-primary"><?php esc_html_e('More posts', 'chic-lifestyle'); ?></button>
				</div>
		<?php }
		}
		?>
  </div>
</div>

<?php get_footer(); ?>