<?php
/**
 * Main template file.
 *
 * Handles the blog home, archives, and search results using the theme's
 * selected archive display mode.
 *
 * @package FansPaysite
 * @since   2.2
 */

get_header();

$archive_display = fanspaysite_get_archive_display();
if ( ! in_array( $archive_display, array( 'classic', 'fullpage', 'boxes' ), true ) ) {
	$archive_display = 'classic';
}
?>

<main id="primary" class="content-area">
	<div class="site-main">
		<?php if ( have_posts() ) : ?>

			<?php if ( 'fullpage' !== $archive_display && ( is_home() || is_archive() || is_search() ) ) : ?>
				<header class="page-header">
					<?php
					if ( is_home() && ! is_front_page() ) {
						single_post_title( '<h1 class="page-title">', '</h1>' );
					} elseif ( is_search() ) {
						printf(
							'<h1 class="page-title">%s</h1>',
							esc_html( sprintf( __( 'Search Results for: %s', 'fanspaysite' ), get_search_query() ) )
						);
					} elseif ( is_archive() ) {
						the_archive_title( '<h1 class="page-title">', '</h1>' );
						the_archive_description( '<div class="archive-description">', '</div>' );
					}
					?>
				</header>
			<?php endif; ?>

			<?php if ( 'fullpage' === $archive_display ) : ?>
				<div id="fps-fullpage" class="fps-fullpage-container">
			<?php elseif ( 'boxes' === $archive_display ) : ?>
				<div class="fps-boxes-grid">
			<?php endif; ?>

			<?php
			while ( have_posts() ) :
				the_post();
				get_template_part( 'template-parts/archive/content', $archive_display );
			endwhile;
			?>

			<?php if ( 'fullpage' === $archive_display || 'boxes' === $archive_display ) : ?>
				</div>
			<?php endif; ?>

			<?php the_posts_navigation(); ?>

		<?php else : ?>

			<?php get_template_part( 'template-parts/content', 'none' ); ?>

		<?php endif; ?>
	</div>
</main>

<?php
get_footer();