<?php
if ( ! get_theme_mod( 'jeweler_shop_enable_slider_section', false ) ) {
	return;
}

$jeweler_shop_slider_category = get_theme_mod( 'jeweler_shop_slider_slider_category', 'slider' );
$jeweler_shop_trending_slider_heading = get_theme_mod( 'jeweler_shop_slider_heading');
$jeweler_shop_args = array(
	'post_type'           => 'post',
	'category_name'       => sanitize_text_field( $jeweler_shop_slider_category ),
	'posts_per_page'      => 3,
	'ignore_sticky_posts' => true,
);

$jeweler_shop_query = new WP_Query( $jeweler_shop_args );

if ( $jeweler_shop_query->have_posts() ) :
	$jeweler_shop_button_label = get_theme_mod( 'jeweler_shop_slider_button_label' );
	$jeweler_shop_button_link  = get_theme_mod( 'jeweler_shop_slider_button_link' );
	$jeweler_shop_button_link  = ! empty( $jeweler_shop_button_link ) ? esc_url( $jeweler_shop_button_link ) : '';
	$jeweler_shop_banner_section_image = get_theme_mod( 'jeweler_shop_slider_image_1');
	$jeweler_shop_banner_section_image_2 = get_theme_mod( 'jeweler_shop_slider_image_2');
	$jeweler_shop_default_image_url = get_template_directory_uri() . '/resource/img/default.png';
	?>
	<section id="jeweler_shop_slider_section" class="slider-section slider-style-1 wow fadeInDown" data-wow-duration="1.5s">
		<?php if ( is_customize_preview() ) : jeweler_shop_section_link( 'jeweler_shop_slider_section' ); endif; ?>
		<div class="slider-section-wrapper">
			<h1 class="banner-side">
				<?php echo esc_html( get_theme_mod( 'jeweler_shop_banner_side_heading', 'Bridal Jewelry' ) ); ?>
			</h1>
			<div class="asterthemes-wrapper">			
				<div class="owl-carousel">
					<?php
					while ( $jeweler_shop_query->have_posts() ) :
						$jeweler_shop_query->the_post();
						?>
						<div class="slider-single-outer">
							<div class="slider-single">
								<div class="slider-img">
									<?php
									if ( has_post_thumbnail() ) {
										the_post_thumbnail( 'full' );
									} else {
										echo '<img src="' . esc_url( get_template_directory_uri() . '/resource/img/default.png' ) . '" alt="' . esc_attr( get_the_title() ) . '">';
									}
									?>
								</div>
								<div class="slider-caption">
									<div class="asterthemes-wrapper">
										<div class="slider-catption-wrapper">
											<?php if ( ! empty( $jeweler_shop_trending_slider_heading ) ) { ?>
												<h3><?php echo esc_html( $jeweler_shop_trending_slider_heading ); ?></h3>
											<?php } ?>
											<h2 class="slider-caption-title">
												<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
											</h2>
											<div class="mag-post-excerpt"><?php the_excerpt(); ?></div>
											<?php if ( ! empty( $jeweler_shop_button_label ) && ! empty( $jeweler_shop_button_link ) ) : ?>
												<div class="banner-slider-btn">
													<a href="<?php echo esc_url( $jeweler_shop_button_link ); ?>" class="asterthemes-button">
														<?php echo esc_html( $jeweler_shop_button_label ); ?>
														<i class="fas fa-arrow-circle-right"></i>
													</a>
												</div>
											<?php endif; ?>
											<div class="slider-images">
												<div class="slider-img-first">
													<img src="<?php echo esc_url( ! empty( $jeweler_shop_banner_section_image ) ? $jeweler_shop_banner_section_image : $jeweler_shop_default_image_url ); ?>"/>
												</div>
												<div class="slider-img-second">
													<img src="<?php echo esc_url( ! empty( $jeweler_shop_banner_section_image_2 ) ? $jeweler_shop_banner_section_image_2 : $jeweler_shop_default_image_url ); ?>"/>
												</div>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
						<?php
					endwhile;
					wp_reset_postdata();
					?>
				</div>
			</div>
		</div>
	</section>
<?php endif; ?>