<?php

if ( ! get_theme_mod( 'aster_travel_blog_enable_travel_section', false ) ) {
	return;
}

$aster_travel_blog_args = '';

aster_travel_blog_render_service_section( $aster_travel_blog_args );

/**
 * Render Service Section.
 */
function aster_travel_blog_render_service_section( $aster_travel_blog_args ) { ?>
	<section id="aster_travel_blog_trending_section" class="asterthemes-frontpage-section trending-section trending-style-1">
		<?php
		if ( is_customize_preview() ) :
			aster_travel_blog_section_link( 'aster_travel_blog_service_section' );
		endif; ?>

		<div class="asterthemes-wrapper">
			<div class="travel-section">
				<?php
					$aster_travel_blog_heading_travel_section = get_theme_mod( 'aster_travel_blog_heading_travel_section');
					if ( ! empty( $aster_travel_blog_heading_travel_section ) ) { ?>
					<h3><?php echo esc_html( $aster_travel_blog_heading_travel_section ); ?></h3>
				<?php } ?>
				<div class="travel-icon-first">
					<i class="fas fa-plane-departure"></i>
				</div>
				<div class="tab">
			        <?php $aster_travel_blog_featured_post = get_theme_mod('aster_travel_blog_travel_number');
			          	for ( $aster_travel_blog_j = 1; $aster_travel_blog_j <= $aster_travel_blog_featured_post; $aster_travel_blog_j++ ){ ?>
		          		<button class="tablinks" onclick="aster_travel_blog_travel_tab(event, '<?php $aster_travel_blog_main_id = get_theme_mod('aster_travel_blog_travel_text'.$aster_travel_blog_j); $aster_travel_blog_tab_id = str_replace(' ', '-', $aster_travel_blog_main_id); echo $aster_travel_blog_tab_id; ?> ')">
			          	<?php echo esc_html(get_theme_mod('aster_travel_blog_travel_text'.$aster_travel_blog_j)); ?></button>
			        <?php }?>
		      	</div>
		  	  	<?php for ( $aster_travel_blog_j = 1; $aster_travel_blog_j <= $aster_travel_blog_featured_post; $aster_travel_blog_j++ ){ ?>
			        <div id="<?php $aster_travel_blog_main_id = get_theme_mod('aster_travel_blog_travel_text'.$aster_travel_blog_j); $aster_travel_blog_tab_id = str_replace(' ', '-', $aster_travel_blog_main_id); echo $aster_travel_blog_tab_id; ?>"  class="tabcontent">
			        	<div class="menus_main_box">
					        <?php $aster_travel_blog_args = array(
								'post_type' => 'post',
								'post_status' => 'publish',
								'category_name' =>  get_theme_mod('aster_travel_blog_travel_category'.$aster_travel_blog_j),
								'posts_per_page' => 4,
								'ignore_sticky_posts' => 1, // Ignore sticky posts
							); ?>
						    <?php $aster_travel_blog_arr_posts = new WP_Query( $aster_travel_blog_args );
						    	if ( $aster_travel_blog_arr_posts->have_posts() ) :
						      	while ( $aster_travel_blog_arr_posts->have_posts() ) :
						        $aster_travel_blog_arr_posts->the_post();
						        ?>
						        <div class="menus_inner_box">
									<?php 
									if ( has_post_thumbnail() ) :
										the_post_thumbnail();
									else : ?>
										<img src="<?php echo esc_url( get_template_directory_uri() . '/resource/img/default.png' ); ?>" alt="<?php the_title(); ?>" />
									<?php endif; ?>
									<div class="menus_content_box">
						        		<h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
						            </div>
						        </div>
						      	<?php
						    endwhile;
						    wp_reset_postdata();
						    endif; ?>
					   	</div>
					</div>
				<?php }?>
				<div class="travel-icon-second">
					<i class="fas fa-book"></i>
				</div>
			</div>
		</div>
	</section>
	<?php
}
?>