<?php

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

$moving_truck_rental_args = '';

moving_truck_rental_render_service_section( $moving_truck_rental_args );

/**
 * Render Service Section.
 */
function moving_truck_rental_render_service_section( $moving_truck_rental_args ) { ?>
	<section id="moving_truck_rental_trending_section" class="asterthemes-frontpage-section trending-section trending-style-1">
		<div class="asterthemes-wrapper">
			<?php
			if ( is_customize_preview() ) :
				moving_truck_rental_section_link( 'moving_truck_rental_service_section' );
			endif;

			$moving_truck_rental_trending_product_heading = get_theme_mod( 'moving_truck_rental_trending_product_heading', '' );
			?>
			<?php if ( ! empty( $moving_truck_rental_trending_product_heading ) ) { ?>
				<div class="product-contact-inner">
					<h3><?php echo esc_html( $moving_truck_rental_trending_product_heading ); ?></h3>
				</div>
			<?php } ?>

		    <div class="tab">
		        <?php $moving_truck_rental_featured_post = get_theme_mod('moving_truck_rental_services_number', '');
		            for ( $moving_truck_rental_j = 1; $moving_truck_rental_j <= $moving_truck_rental_featured_post; $moving_truck_rental_j++ ){ ?>
		            <button class="tablinks" onclick="moving_truck_rental_services_tab(event, '<?php $moving_truck_rental_main_id = get_theme_mod('moving_truck_rental_services_text'.$moving_truck_rental_j); $moving_truck_rental_tab_id = str_replace(' ', '-', $moving_truck_rental_main_id); echo $moving_truck_rental_tab_id; ?> ')">
		            <?php echo esc_html(get_theme_mod('moving_truck_rental_services_text'.$moving_truck_rental_j)); ?></button>
		        <?php }?>
		    </div>

		    <?php for ( $moving_truck_rental_j = 1; $moving_truck_rental_j <= $moving_truck_rental_featured_post; $moving_truck_rental_j++ ){ 
		        $moving_truck_rental_catData = get_theme_mod('moving_truck_rental_trending_post_category'.$moving_truck_rental_j,'');
		        ?>
		        <div id="<?php $moving_truck_rental_main_id = get_theme_mod('moving_truck_rental_services_text'.$moving_truck_rental_j); $moving_truck_rental_tab_id = str_replace(' ', '-', $moving_truck_rental_main_id); echo $moving_truck_rental_tab_id; ?>" class="tabcontent">
		            <div class="services_main_box">
		                <div class="owl-carousel">
		                <?php  $moving_truck_rental_args = array(
		                    'post_type' => 'post', // Changed from 'product' to 'post'
		                    'posts_per_page' => 10,
		                    'category_name' => $moving_truck_rental_catData, // Filter by category slug
		                    'order' => 'ASC'
		                );?>
		                    <?php $moving_truck_rental_loop = new WP_Query( $moving_truck_rental_args );
		                    while ( $moving_truck_rental_loop->have_posts() ) : $moving_truck_rental_loop->the_post(); ?>
		                        <div class="tab-post">
		                            <figure>
		                                <?php if ( has_post_thumbnail() ) : ?>
										    <?php the_post_thumbnail( 'full' ); ?>
										<?php else : ?>
										    <img src="<?php echo esc_url( get_template_directory_uri() ); ?>/resource/img/default.jpg" alt="Default Image" />
										<?php endif; ?>
		                            </figure>
		                            <h5 class="post-text"><a href="<?php echo esc_url(get_permalink( $moving_truck_rental_loop->post->ID )); ?>"><?php the_title(); ?></a></h5>
		                            <div class="excerpt-content">
		                            	<?php the_excerpt(); ?>
		                            </div>
		                        </div>
		                    <?php endwhile; wp_reset_postdata(); ?>
		                </div>
		            </div>
		        </div>
		    <?php }?>
		</div>	    	
	</section>
	<?php
}