<?php
/**
 * Template Post Type: post
 *
 * @package wpstream-theme
 */

get_header();

$wpstream_blog_post_sidebar = wpstream_theme_is_show_sidebar();

$show_author_section         = get_theme_mod( 'wpstream_blog_post_show_author_section', true );
$show_related_posts_section  = get_theme_mod( 'wpstream_blog_post_show_related_posts_section', true );
$show_latest_posts_section   = get_theme_mod( 'wpstream_blog_post_show_latest_posts_section', true );
$show_trending_posts_section = get_theme_mod( 'wpstream_blog_post_show_trending_posts_section', true );

$image_id  = get_post_thumbnail_id( $post->ID );
$image_url = wp_get_attachment_image_src( $image_id, 'wpstream_featured_blog_image' );
?>


	<section class="wpstream_section wp-stream-blog-content">
		<div class="<?php echo esc_attr( wpstream_theme_container_class() ); ?>">

			<?php
			if ( have_posts() ) :
				while ( have_posts() ) :
					the_post();
					?>

		
			<div class="row">
					<?php if ( $wpstream_blog_post_sidebar ) { ?>

				<div class="col-12 col-lg-9 wp-stream-blog-content-extra-padding">

					<?php } else { ?>

					<div class="col-12">

						<?php } ?>

						<?php
						if ( isset( $image_url[0] ) ) { ?>
							<section class="wpstream_section wpstream_featured_image_banner">
								<img class="wpstream_featured_image" src="<?php echo esc_url( $image_url[0] ); ?>" alt="<?php echo esc_attr('featured image','hello-wpstream');?>">
								<div class="wpstream_player_container_gradient"></div>
								<div class="wpstream_title_wrapper_simple">
									<?php
										include get_template_directory() . '/template-parts/single/post-author-content-simple.php';
									?>
									<h1 class="wpstream-main-title"><?php the_title(); ?></h1>
									
								</div>

							</section>
						<?php
						}else{
							?>
							<h1 class="wpstream-main-title"><?php the_title(); ?></h1>
							<?php
						}
						?>

							
				
						<!-- Author Information Section -->
				

						<!-- Post Additional Information Section -->
						<?php include get_template_directory() . '/template-parts/single/post-additional-content.php'; ?>

						<!-- Post Additional Information Section -->
						<div id="content" class="wpstream-post-content">
						
							
							<?php
							if ( get_the_content() ) {
								the_content();

								// Add wp_link_pages to display pagination for multi-page posts
								wp_link_pages( array(
									'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'hello-wpstream' ),
									'after'  => '</div>',
								) );
								
							} else {
								echo esc_html__( 'No content', 'hello-wpstream' );
							}
							?>

						</div>
						<!-- share blog post -->
						<div class="wpstream-single-post-bar wpstream-single-post-bar-bottom">
							<div class="row align-items-center justify-content-center justify-content-md-between">
								<div class="col-12 col-md-6">
									<p class="m-0"><?php esc_html_e( 'Share this blog post', 'hello-wpstream' ); ?></p>

								</div>
								<div class="col-12 col-md-6">
									<div class="wp-stream-social-icons wp-stream-list-right">

										<?php echo wpstream_theme_show_social_share_page( $post->ID, 'full', 0 ); ?>

									</div>
								</div>
							</div>
						</div>
						<!-- Author Information Section -->
							<?php include get_template_directory() . '/template-parts/single/post-comments.php'; ?>

					</div>
						<?php if ( $wpstream_blog_post_sidebar ) { ?>

							<?php get_sidebar(); ?>

					<?php } ?>

				</div>
					<?php
				endwhile;
				wp_reset_postdata();
				?>

				<?php else : ?>

					<p><?php esc_html_e( 'Sorry, no posts matched your criteria.', 'hello-wpstream' ); ?></p>

				<?php endif; ?>

			</div>
	</section>

<?php if ( $show_author_section ) : ?>
	<section class="wpstream_section wpstream_author_section m-0">
		<div class="<?php echo esc_attr( wpstream_theme_container_class() ); ?>">

			<div class="row gx-5">
				<div class="col-12 col-sm-6 col-md-3">
					<div class="wpstream-title-author_section mb-3 mb-md-0">
						<h3 class="mb-2rem"><?php esc_html_e( 'Published in', 'hello-wpstream' ); ?></h3>

						<?php the_category( '', 'single' ); ?>

					</div>
				</div>
				<div class="col-12 col-sm-6 col-md-9">
					<div class="wpstream-title-author_section mb-2rem">
						<h2 class="mb-2rem"><?php esc_html_e( 'The author', 'hello-wpstream' ); ?></h2>

						<?php
						$author_id   = $post->post_author;
						$image_url   = wpstream_get_author_profile_image_url_by_author_id( $author_id, 48 );
						$author_url  = get_author_posts_url( $author_id );
						$author_name = get_the_author_meta( 'display_name', $author_id );

						?>

						<div class="wpstream-title-author-details-wrapper">
							<a class="wpstream_author flex-shrink-0" href="<?php echo esc_url( $author_url ); ?>">

								<img src="<?php echo esc_attr( $image_url ); ?>" alt="<?php echo esc_attr( $author_name ); ?>" width="48" height="48">

							</a>
							<div class="wpstream_author_wrapper_name flex-grow-1">
								<a class="d-inline-block" href="<?php echo esc_url( $author_url ); ?>">

									<?php echo esc_html( $author_name ); ?>

								</a>

								<?php if ( get_the_author_meta( 'description', $author_id ) ) : ?>

									<p class="m-0">
										<?php the_author_meta( 'description', $author_id ); ?>
									</p>

								<?php endif; ?>

							</div>
						</div>
					</div>
					<div class="wpstream-grid-main wpstream-author-posts">
						<h2 class="title-more">
							<?php esc_html_e( 'More from this author', 'hello-wpstream' ); ?>

							<a href="<?php echo esc_url( wpstream_get_single_post_author_link( $post->ID ) ); ?>">

								<?php esc_html_e( 'See more', 'hello-wpstream' ); ?>
								<?php echo wpstream_theme_get_svg_icon( 'right-arrow.svg' ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>

							</a>
						</h2>
						<div class="row">
							<?php wpstream_theme_more_from_author( $author_id, 'col-12' ); ?>
						</div>
					</div>
				</div>
			</div>
		</div>
	</section>
<?php endif; ?>
<?php

if ( $show_related_posts_section ) {
	$wpstream_section_title = esc_html__( 'Related Blog Posts', 'hello-wpstream' );
	require get_template_directory() . '/template-parts/single/section/post-related-content.php';
}

if ( $show_latest_posts_section ) {
	$wpstream_section_title = esc_html__( 'Latest Blog Posts', 'hello-wpstream' );
	require get_template_directory() . '/template-parts/single/section/post-latest-content.php';
}

if ( $show_trending_posts_section ) {
	$wpstream_section_title = esc_html__( 'Trending Blog Posts', 'hello-wpstream' );
	require get_template_directory() . '/template-parts/single/section/post-trending-content.php';
}

get_footer();
