<?php
/**
 * Template part for displaying home testimonials section
 *
 * @package Education_Soul
 */

$testimonials_title    = education_soul_get_option( 'testimonials_title' );
$testimonials_number   = education_soul_get_option( 'testimonials_number' );
$testimonials_category = education_soul_get_option( 'testimonials_category' );
?>
<div id="education-soul-testimonials" class="home-section home-section-testimonials">
	<div class="container">
		<h2 class="section-title"><?php echo esc_html( $testimonials_title ); ?></h2>
		<?php
		$qargs = array(
			'posts_per_page'      => absint( $testimonials_number ),
			'no_found_rows'       => true,
			'ignore_sticky_posts' => true,
		);

		if ( absint( $testimonials_category ) > 0 ) {
			$qargs['cat'] = absint( $testimonials_category );
		}

		// Fetch posts.
		$the_query = new WP_Query( $qargs );
		?>
		<?php if ( $the_query->have_posts() ) : ?>
			<?php
			$carousel_args = array(
				'slidesToShow'   => 3,
				'slidesToScroll' => 1,
				'dots'           => false,
				'prevArrow'      => '<span class="left-arrow carousel-arrow"><i class="fas fa-angle-left" aria-hidden="true"></i></span>',
				'nextArrow'      => '<span class="right-arrow carousel-arrow"><i class="fas fa-angle-right" aria-hidden="true"></i></span>',
				'responsive'     => array(
					array(
						'breakpoint' => 1024,
						'settings'   => array(
							'slidesToShow' => 2,
						),
					),
					array(
						'breakpoint' => 768,
						'settings'   => array(
							'slidesToShow' => 1,
						),
					),
					array(
						'breakpoint' => 480,
						'settings'   => array(
							'slidesToShow' => 1,
						),
					),
				),
			);

			if ( is_rtl() ) {
				$carousel_args['rtl'] = true;
			}

			$carousel_args_encoded = wp_json_encode( $carousel_args );
			?>

			<div class="testimonials-wrapper">
				<div class="inner-wrapper">
					<div class="education-soul-carousel" data-slick='<?php echo $carousel_args_encoded; ?>'>
						<?php
						while ( $the_query->have_posts() ) :
							$the_query->the_post();
							?>
							<div class="testimonials-item">
								<div class="testimonials-item-inner">
									<div class="testimonials-content-area">
										<?php the_excerpt(); ?>
									</div><!-- .testimonials-content-area -->
									<div class="testimonial-main-wrap">
										<?php if ( has_post_thumbnail() ) : ?>
											<a class="testimonials-thumb" href="<?php the_permalink(); ?>"><?php the_post_thumbnail( 'thumbnail' ); ?></a>
										<?php else : ?>
											<a class="testimonials-thumb" href="<?php the_permalink(); ?>"><img src="<?php echo esc_url( get_template_directory_uri() . '/images/user.png' ); ?>" alt="<?php the_title_attribute(); ?>" /></a>
										<?php endif; ?>
										<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
										<div class="testimonial-rating">
											<i class="fas fa-star"></i>
											<i class="fas fa-star"></i>
											<i class="fas fa-star"></i>
											<i class="fas fa-star"></i>
											<i class="fas fa-star"></i>
										</div>
									</div><!-- .testimonial-main-wrap -->
								</div><!-- .testimonials-item-inner -->
							</div><!-- .testimonials-item -->

						<?php endwhile; ?>
					</div><!-- .education-soul-carousel -->
				</div><!-- .inner-wrapper -->
			</div><!-- .testimonials-wrapper -->
			<?php wp_reset_postdata(); ?>

		<?php endif; ?>

	</div><!-- .container -->
</div><!-- .home-section-testimonials -->
