<?php
/**
 * Template part for displaying single posts.
 *
 * @package bootstrap_coach
 */

?>

  <h1 class="page-title"><?php the_title(); ?></h1>

<div class="single-post">

	<?php
	$post_options = get_theme_mod( 'bootstrap_coach_post_details', array( 'date', 'categories', 'tags', 'author_block' ) );
	$featured_image_position = get_theme_mod( 'bootstrap_coach_featured_image_position', 'center' );
	if ( $featured_image_position === 'left' ) {
		$featured_image_position_class = 'justify-content-start';
	} elseif ( $featured_image_position === 'right' ) {
		$featured_image_position_class = 'justify-content-end';
	} else {
		$featured_image_position_class = 'justify-content-center';
	}
	?>

	<?php if ( ! empty( $post_options ) ) : ?>
		<div class="info">
			<ul class="list-inline">

				<?php if ( in_array( 'author', $post_options ) ) : ?>
					<li>
						<a class="url fn n" href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>">
							<?php $avatar = get_avatar( get_the_author_meta( 'ID' ), 60 ); ?>
							<?php if ( $avatar ) : ?>
								<span class="fa fa-user"></span>
							<?php endif; ?>
							<?php echo esc_html( get_the_author() ); ?>
						</a>
					</li>
				<?php endif; ?>

				<?php if ( in_array( 'date', $post_options ) ) : ?>
					<?php $archive_year = get_the_time( 'Y' ); $archive_month = get_the_time( 'm' ); $archive_day = get_the_time( 'd' ); ?>
					<li><span class="fa fa-clock-o"></span> <a href="<?php echo esc_url( get_day_link( $archive_year, $archive_month, $archive_day ) ); ?>"><?php echo get_the_date( 'F j, Y' ); ?></a></li>
				<?php endif; ?>

				<?php if ( in_array( 'number_of_comments', $post_options ) ) : ?>
					<li><span class="fa fa-comment-o"></span> <?php comments_popup_link( __( 'zero comment', 'bootstrap-coach' ), __( 'one comment', 'bootstrap-coach' ), __( '% comments', 'bootstrap-coach' ) ); ?></li>
				<?php endif; ?>

				<?php if ( in_array( 'categories', $post_options ) ) : ?>
					<?php $categories = get_the_category();
					if ( ! empty( $categories ) ) :
						foreach ( $categories as $category ) { ?>
							<li><a href="<?php echo esc_url( get_category_link( $category->term_id ) ); ?>"><?php echo esc_html( $category->name ); ?></a></li>
						<?php }
					endif; ?>
				<?php endif; ?>

				<?php if ( in_array( 'tags', $post_options ) ) : ?>
					<?php $tags = get_the_tags();
					if ( ! empty( $tags ) ) :
						foreach ( $tags as $tag ) { ?>
							<li><a href="<?php echo esc_url( get_category_link( $tag->term_id ) ); ?>"><?php echo esc_html( $tag->name ); ?></a></li>
						<?php }
					endif; ?>
				<?php endif; ?>

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

	<div class="post-content">
		<?php if ( has_post_thumbnail() ) : ?>
			<figure class="feature-image d-flex <?php echo esc_attr( $featured_image_position_class ); ?>" id="featured-image">
				<?php the_post_thumbnail( 'full', array( 'class' => 'featured-image' ) ); ?>
			</figure>
		<?php endif; ?>

		<article>
			<?php the_content(); ?>

			<?php
			wp_link_pages( array(
				'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'bootstrap-coach' ),
				'after'  => '</div>',
			) );
			?>
		</article>
	</div>

	<?php if ( ! empty( $post_options ) && in_array( 'author_block', $post_options ) ) : ?>
		<div class="author-post clearfix">
			<?php $avatar = get_avatar( get_the_author_meta( 'ID' ), 75 ); ?>
			<?php if ( $avatar ) : ?>
				<div class="author-image">
					<a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>"><?php echo $avatar; ?></a>
				</div>
			<?php endif; ?>
			<div class="author-details">
				<h6><a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>"><?php echo esc_html( get_the_author() ); ?></a></h6>
				<p><?php echo esc_html( get_the_author_meta( 'description' ) ); ?></p>
			</div>
		</div>
	<?php endif; ?>

</div>
