<?php
/**
 * Template part for displaying Featured Classes Section
 *
 * @package Travel Planning
 */

$travel_planning_classes       = get_theme_mod( 'travel_planning_classes_setting', false );
$travel_planning_service_title = get_theme_mod( 'travel_planning_service_title' );
$travel_planning_service_text  = get_theme_mod( 'travel_planning_service_text' );
$travel_planning_destination_btn_url    = get_theme_mod( 'travel_planning_destination_btn_url' );
$travel_planning_destination_button_text = get_theme_mod( 'travel_planning_destination_button_text' );
?>

<?php if ( $travel_planning_classes ) : ?>
<div id="topdestination" class="our-classes">
  <div class="container">

    <?php if ( $travel_planning_service_title || $travel_planning_service_text ) : ?>
      <div class="destination-info mb-3">
        <div class="section-title">
          <?php if ( $travel_planning_service_title ) : ?>
            <h2><?php echo esc_html( $travel_planning_service_title ); ?></h2>
          <?php endif; ?>
          <?php if ( $travel_planning_service_text ) : ?>
            <p><?php echo esc_html( $travel_planning_service_text ); ?></p>
          <?php endif; ?>
        </div>
        <div class="destination-btn">
          <?php if ( $travel_planning_destination_button_text && $travel_planning_destination_btn_url ) : ?>
              <a href="<?php echo esc_url( $travel_planning_destination_btn_url ); ?>">
                  <?php echo esc_html( $travel_planning_destination_button_text ); ?>
                  <i class="fas fa-chevron-right"></i>
              </a>
          <?php endif; ?>
        </div>
      </div>
    <?php endif; ?>

    <div class="owl-carousel destination-slider">
      <?php
        $travel_planning_catergory_name = get_theme_mod( 'travel_planning_blog_args_' );
        $travel_planning_args = array(
            'post_type'           => 'post',
            'category_name'       => $travel_planning_catergory_name,
            'orderby'             => 'post__in',
            'ignore_sticky_posts' => true,
        );

        $travel_planning_query = new WP_Query( $travel_planning_args );
        $travel_planning_count = 1;

        if ( $travel_planning_query->have_posts() ) :
          while ( $travel_planning_query->have_posts() ) :
            $travel_planning_query->the_post();
      ?>
        <div class="item">
          <div class="destination_box wow zoomIn" data-wow-duration="1.5s">

            <div class="image-blog destination-image">
              <?php 
              if ( has_post_thumbnail() ) {
                  the_post_thumbnail( 'large' );
              } else {

                  ?>
                  <img src="<?php echo esc_url( get_stylesheet_directory_uri() . '/images/default.png' ); ?>" alt="<?php the_title_attribute(); ?>">
              <?php } ?>

              <span class="counter">
                <?php echo esc_html( sprintf( '%02d', $travel_planning_count ) ); ?>
              </span>
            </div>

            <div class="destination_content">
              <div class="destination_content_inner">
                <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                <p><?php echo esc_html( wp_trim_words( get_the_excerpt(), 15 ) ); ?></p>
              </div>
            </div>

          </div>
        </div>
      <?php
            $travel_planning_count++;
          endwhile;
          wp_reset_postdata();
        endif;
      ?>
    </div>
  </div>
</div>
<?php endif; ?>