<?php
/**
 * Front page template for the single-page layout.
 *
 * Each top-level item of the primary menu that points to a page
 * becomes a section in this template.
 */

get_header();

$sections = tents_singlepage_get_sections();
?>

<div id="primary" class="content-area">
	<main id="main" class="site-main" role="main">
		<?php
		if ( ! empty( $sections ) ) {
			$index = 0;

			foreach ( $sections as $section ) {
				$index++;

				// Provide section data to the template part.
				set_query_var(
					'tents_singlepage_section',
					array(
						'id'      => $section['id'],
						'slug'    => $section['slug'],
						'title'   => $section['title'],
						'content' => $section['content'],
						'page_id' => $section['page_id'],
						'index'   => $index,
					)
				);

				get_template_part( 'template-parts/section', 'generic' );
			}

			// Reset global post if it was altered.
			wp_reset_postdata();
		} else {
			// Fallback: show default page content if no menu sections are available.
			if ( have_posts() ) {
				while ( have_posts() ) {
					the_post();
					get_template_part( 'template-parts/page/content', 'front-page' );
				}
			}
		}
		?>
	</main><!-- #main -->
</div><!-- #primary -->

<?php
get_footer();

