<?php
/**
 * Front page template.
 *
 * Respects Appearance → Customize → Homepage Settings:
 * - Your latest posts: banner + Solar Services + Plan A blog (featured + rows) + sidebar
 * - A static page: banner + Solar Services + selected page content
 *
 * @package ttsunsolar
 */

get_header();
?>

<?php if ( is_home() ) : ?>
	<section class="section section--blog-home">
		<div class="container content-layout content-layout--blog-home">
			<div class="site-main">
				<?php if ( have_posts() ) : ?>
					<header class="blog-home-heading">
						<p class="section_tagline"><?php esc_html_e( 'From the blog', 'ttsunsolar' ); ?></p>
						<h2><?php esc_html_e( 'Latest Articles', 'ttsunsolar' ); ?></h2>
					</header>

					<div class="blog-home-feed">
						<?php
						$ttsunsolar_post_index = 0;
						while ( have_posts() ) :
							the_post();
							if ( 0 === $ttsunsolar_post_index ) {
								get_template_part( 'solarpanels/content/panel', 'content-featured' );
							} else {
								get_template_part( 'solarpanels/content/panel', 'content-row' );
							}
							++$ttsunsolar_post_index;
						endwhile;
						?>
					</div>
					<?php ttsunsolar_posts_pagination(); ?>
				<?php else : ?>
					<p><?php esc_html_e( 'Nothing found.', 'ttsunsolar' ); ?></p>
				<?php endif; ?>
			</div>
			<?php get_sidebar(); ?>
		</div>
	</section>
<?php else : ?>
	<?php
	while ( have_posts() ) :
		the_post();
		$page_content = get_the_content();
		$page_content = trim( (string) $page_content );
		if ( '' === $page_content && ! has_post_thumbnail() && ! comments_open() && ! get_comments_number() ) {
			continue;
		}
		?>
		<section class="section section--homepage-page">
			<div class="container content-layout content-layout--page">
				<div class="site-main site-main--full">
					<article id="post-<?php the_ID(); ?>" <?php post_class( 'single-entry homepage-page' ); ?>>
						<?php if ( get_the_title() ) : ?>
							<header class="entry-header">
								<h1 class="entry-title"><?php the_title(); ?></h1>
							</header>
						<?php endif; ?>
						<?php if ( has_post_thumbnail() ) : ?>
							<div class="entry-thumb">
								<?php the_post_thumbnail( 'large' ); ?>
							</div>
						<?php endif; ?>
						<div class="entry-content">
							<?php
							the_content();
							wp_link_pages(
								array(
									'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'ttsunsolar' ),
									'after'  => '</div>',
								)
							);
							?>
						</div>
					</article>
					<?php
					if ( comments_open() || get_comments_number() ) {
						comments_template();
					}
					?>
				</div>
			</div>
		</section>
		<?php
	endwhile;
	?>
<?php endif; ?>

<?php
get_footer();
