<?php 
/**  
 * The template used for displaying page content in page.php  
 *  
 * @package Travel Tour
 */

?>

<h1><?php the_title(); ?></h1>

<div class="flex flex-column">

	<?php $post_options = get_theme_mod( 'travel_tour_post_details', array( 'date', 'categories', 'tags', 'author_block' ) ); ?>
	<?php if ( ! empty( $post_options ) ) : ?>
	<div class="d-flex flex-row flex-wrap mb-24 lh-sm">

		<?php if ( in_array( 'date', $post_options, true ) ) : ?>
		<?php $archive_year = get_the_time('Y'); $archive_month = get_the_time('m'); $archive_day = get_the_time('d'); ?>
		<span class="me-16">
			<i class="fa fa-clock-o text-primary"></i>
			<a href="<?php echo esc_url( get_day_link( $archive_year, $archive_month, $archive_day ) ); ?>" class="text-dark text-opacity-50"><?php echo get_the_date(); ?></a>
		</span>
		<?php endif; ?>

		<?php if ( in_array( 'author', $post_options, true ) ) : ?>
		<span class="me-16">
			<a class="text-dark text-opacity-50" href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>">
				<?php $avatar = get_avatar( get_the_author_meta( 'ID' ), $size = 60 ); ?>
				<?php if ( $avatar ) : ?>
					<i class="fa fa-user text-primary"></i>
				<?php endif; ?>
				<?php echo esc_html( get_the_author() ); ?>
			</a>
		</span>
		<?php endif; ?>

		<?php if ( in_array( 'number_of_comments', $post_options, true ) ) : ?>
		<span class="me-16 text-dark text-opacity-50">
			<i class="fa fa-comments-o text-primary"></i>
			<?php comments_popup_link( __( 'zero comment', 'travel-tour' ), __( 'one comment', 'travel-tour' ), __( '% comments', 'travel-tour' ), 'text-dark text-opacity-50' ); ?>
		</span>
		<?php endif; ?>

		<?php if ( in_array( 'categories', $post_options, true ) ) : ?>
		<?php $categories = get_the_category();
		if ( ! empty( $categories ) ) :
			foreach ( $categories as $cat ) { ?>
				<span class="me-16">
					<a href="<?php echo esc_url( get_category_link( $cat->term_id ) ); ?>" class="text-dark text-opacity-50"><?php echo esc_html( $cat->name ); ?></a>
				</span>
			<?php }
		endif; ?>
		<?php endif; ?>

		<?php if ( in_array( 'tags', $post_options, true ) ) : ?>
		<?php $tags = get_the_tags();
		if ( ! empty( $tags ) ) :
			foreach ( $tags as $tag ) { ?>
				<span class="me-16">
					<a href="<?php echo esc_url( get_category_link( $tag->term_id ) ); ?>" class="text-dark text-opacity-50"><?php echo esc_html( $tag->name ); ?></a>
				</span>
			<?php }
		endif; ?>
		<?php endif; ?>

	</div>
	<?php endif; ?>

	<div class="post-content">

		<?php
      $featured_image_position = get_theme_mod( 'travel_tour_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 ( has_post_thumbnail() ) : ?>
    <figure class="mb-32 d-flex <?php echo esc_attr( $featured_image_position_class ); ?>">
      <?php the_post_thumbnail( 'full', array('class' => 'featured-image object-fit-cover object-position-center') ); ?>
    </figure>
    <?php endif; ?>

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

	</div>

	<?php if ( get_edit_post_link() ) : ?>
		<div class="mt-32">
			<?php edit_post_link( __( 'Edit', 'travel-tour' ), '<span class="edit-link">', '</span>' ); ?>
		</div><!-- .entry-meta -->
	<?php endif; ?>

</div>