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

?>

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

<div class="single-post">
  <?php $post_options = get_theme_mod( 'chic_lifestyle_post_details', array( 'date', 'categories', 'tags', 'author_block' ) ); ?>
  <?php if ( ! empty( $post_options ) ) : ?>   

    <div class="info fs-85 text-info">
      <ul class="list-inline d-flex flex-wrap gap-8 m-0">
         <?php foreach ( $post_options as $key => $value ) : ?>

            <?php if( $value == 'author' ) { ?>
              <li>
                <a class="text-primary 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'),
                  20,
                  '',
                  '',
                  array('class' => 'rounded-circle h-20 w-20')
                ); ?>
                  <?php if( $avatar ) : ?>
                    <div class="author-image float-start me-2 w-20 h-20"> 
                      <?php echo $avatar; ?>
                    </div>
                  <?php endif; ?>
                  <?php echo esc_html( get_the_author() ); ?>
                </a>
             </li>
            <?php } ?>

            <?php if( $value == 'date' ) { ?>
              <?php $archive_year  = get_the_time('Y'); $archive_month = get_the_time('m'); $archive_day = get_the_time('d'); ?>
              <li><i class="fa fa-clock-o"></i> <a href="<?php echo esc_url( get_day_link( $archive_year, $archive_month, $archive_day ) ); ?>"><?php echo get_the_date(); ?></a></li>
            <?php } ?>

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

            <?php if( $value == 'tags' ) { ?>
              <?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 } ?>
            

            <?php if( $value == 'number_of_comments' ) { ?>
              <li><i class="fa fa-comments-o"></i> <?php comments_popup_link( __( 'zero comment', 'chic-lifestyle' ), __( 'one comment', 'chic-lifestyle' ), __( '% comments', 'chic-lifestyle' ) ); ?></li>
            <?php } ?>            

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

  <?php endif; ?>


  <div class="post-content">
    <?php if ( has_post_thumbnail() ) { ?>
      <figure class="pt-8 ps-0">        
          <?php the_post_thumbnail('full', ['class' => "w-p100 rounded-0 object-fit-cover"]); ?>
      </figure>
    <?php } ?>
    
    <article>
      <?php the_content(); ?>
      
      <?php
        wp_link_pages( array(
          'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'chic-lifestyle' ),
          'after'  => '</div>',
        ) );
      ?>     
    </article>

    </div>

    <?php if( in_array( 'author_block', $post_options ) ) : ?>
      <div class="clearfix px-32 pt-32 pb-16 my-32 border border-light-subtle">
        <?php $avatar = get_avatar( get_the_author_meta('ID'), 75, '', '', [ 'class' => 'rounded-circle' ] ); ?>
        <?php if( $avatar ) : ?>
          <div class="float-start w-64"> 
            <a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>"><?php echo $avatar; ?></a>
          </div>
        <?php endif; ?>
        <div class="overflow-hidden px-32">
          <h4 class="mb-16"><a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>"><?php echo esc_html( get_the_author() ); ?></a></h4>
          <p class="text-muted"><?php echo esc_html( get_the_author_meta('description') ); ?></p>
        </div>
      </div>
    <?php endif; ?>


  </div>