<?php
/**
 * The front page template file.
 */

get_header();

$hero_bg = get_theme_mod('hero_background_image', get_template_directory_uri() . '/assets/images/hero-default.png');
?>

<section class="hero-section text-white d-flex align-items-center position-relative"
	style="background-image: linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.6)), url('<?php echo esc_url($hero_bg); ?>'); background-size: cover; background-position: center; min-height: 80vh;">
	<div class="container text-center py-5">
		<h1 class="display-3 fw-bold mb-4 font-serif text-white">
			<?php echo get_theme_mod('hero_headline', 'Ancient Wisdom for a Modern World.'); ?>
		</h1>
		<p class="lead fw-normal mb-5 w-75 mx-auto font-sans text-light">
			<?php echo get_theme_mod('hero_subheadline', 'A collection of biblical insights curated for the thoughtful leader.'); ?>
		</p>
		<a href="#primary"
			class="btn btn-secondary btn-lg px-5 py-3 rounded-pill text-uppercase fw-bold shadow-sm"><?php echo get_theme_mod('hero_cta_text', 'Start Reading'); ?></a>
	</div>
</section>

<div class="container my-5 py-4">
	<main id="primary" class="site-main">
		<header class="text-center mb-5">
			<h2 class="display-5 fw-bold font-serif mb-3">Seek Truth. Lead with Grace.</h2>
			<p class="lead text-muted font-sans font-italic">Explorations into the heart of the Kingdom.</p>
		</header>

		<div class="row g-4 mb-5">
			<?php
			if (have_posts()):
				while (have_posts()):
					the_post();
					?>
					<?php get_template_part('template-parts/content', 'card'); ?>
					<?php
				endwhile;

				echo '</div>'; // close row
			
				the_posts_navigation(array(
					'screen_reader_text' => 'Posts navigation',
					'prev_text' => '<span class="btn btn-outline-primary">&larr; Older Posts</span>',
					'next_text' => '<span class="btn btn-outline-primary">Newer Posts &rarr;</span>',
					'class' => 'd-flex justify-content-between my-5'
				));
			else:
				echo '<div class="col-12"><div class="alert alert-info text-center">' . esc_html__('No posts found.', 'wisdom1') . '</div></div></div>';
			endif;
			?>
	</main><!-- #main -->
</div><!-- .container -->

<?php if (get_theme_mod('show_author_section', true)): ?>
	<section class="author-section py-5 bg-light border-top border-bottom">
		<div class="container text-center py-4">
			<?php $author_image = get_theme_mod('author_image_url', ''); ?>
			<?php if ($author_image): ?>
				<img src="<?php echo esc_url($author_image); ?>"
					alt="<?php echo esc_attr(get_theme_mod('author_name', 'David Clemetson')); ?>"
					class="rounded-circle mb-4 shadow-sm"
					style="width: 150px; height: 150px; object-fit: cover; border: 4px solid white;">
			<?php else: ?>
				<div class="rounded-circle mb-4 shadow-sm mx-auto bg-secondary d-flex align-items-center justify-content-center text-white display-4"
					style="width: 150px; height: 150px; border: 4px solid white;">
					<?php
					$name = get_theme_mod('author_name', 'David Clemetson');
					echo esc_html(substr($name, 0, 1));
					?>
				</div>
			<?php endif; ?>
			<h2 class="display-6 fw-bold font-serif mb-3 text-dark">
						<?php echo esc_html(get_theme_mod('author_name', 'David Clemetson')); ?></h2>
			<p class="lead font-sans text-muted mx-auto" style="max-width: 680px;">
				<?php echo wp_kses_post(get_theme_mod('author_bio', 'Exploring the intersection of faith, leadership, and modern life. Join me on a journey to uncover timeless wisdom.')); ?>
			</p>
		</div>
	</section>
<?php endif; ?>

<?php get_template_part('template-parts/newsletter'); ?>

<?php
get_footer();
