<?php
/**
 * Template part for displaying posts grid view
 *
 * @package Travel Tour
 */
$post_details = get_theme_mod( 'blog_post_show_hide_details', array( 'date', 'categories', 'tags' ) );

?>
<div id="post-<?php the_ID(); ?>" class="g-col-12 d-flex flex-column justify-content-start align-items-start flex-nowrap overflow-hidden mb-20">
    
  <div class="w-p100 h-280 h-sm-320 h-md-500 h-lg-600 bg-info bg-opacity-25">
    <?php if ( has_post_thumbnail() ) : ?>
      <a href="<?php echo esc_url( get_permalink() ); ?>" rel="bookmark" class="w-p100 h-p100 d-block overflow-hidden">
        <?php the_post_thumbnail( 'post-thumbnail', array('class' => 'w-p100 h-p100 object-fit-cover object-position-center') ); ?>
      </a>            
    <?php endif; ?>
  </div>
  <div class="w-p100 d-flex flex-column justify-content-start align-items-start flex-nowrap px-12 py-16">
  
  <?php if( in_array( 'categories', $post_details ) ) { ?>
    <?php $categories = get_the_category();
      if( ! empty( $categories ) ) : ?>
      <div class="d-inline-flex mb-12 lh-sm">
        <?php foreach ( $categories as $cat ) { ?>
           <span class="me-8"><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 } ?>
      </div>
      <?php endif; ?>
    <?php } ?>       
      
      <h2 class="mb-12 lh-sm"><a href="<?php echo esc_url( get_permalink() ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
          
      <?php if( is_array( $post_details ) && ! empty( $post_details ) ) : ?>
      <div class="d-inline-flex mb-12 lh-sm">
        <?php if( in_array( 'date', $post_details ) ) { ?>
          <?php
            $archive_year  = get_the_time('Y');
            $archive_month = get_the_time('m');
            $archive_day = get_the_time('d');
          ?>
          <span class="me-8">
            <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 } ?>

        <?php if( in_array( 'tags', $post_details ) ) { ?>
          <?php $tags = get_the_tags();
            if( ! empty( $tags ) ) :
              foreach ( $tags as $tag ) { ?>
                <span class="me-8">
                  <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 } ?>
            
        <?php if( in_array( 'number_of_comments', $post_details ) ) { ?>
          <span class="text-dark text-opacity-50 me-8">
            <i class="fa fa-comments-o text-primary"></i>
            <?php comments_popup_link( __( 'zero comment', 'travel-tour' ), __( 'one comment', 'travel-tour' ), __( '% comments', 'travel-tour' ) ); ?>
          </span>
        <?php } ?>
      </div>
      <?php endif; ?>        
      
      <div class=""><?php the_excerpt(); ?></div>
      
      <div class="text-dark text-uppercase fs-6"><a href="<?php echo esc_url( the_permalink() ); ?>"><?php esc_html_e('Read more','default'); ?></a></div>

    </div>
</div>
