<?php
/**
 * The template for displaying testimonial items
 *
 * @package Signify
 */

$signify_number = get_theme_mod( 'signify_testimonial_number', 5 );

if ( ! $signify_number ) {
	// If number is 0, then this section is disabled
	return;
}
?>

<div class="testimonial-slider-wrapper">
	<div class="section-content-wrapper testimonial-content-wrapper testimonial-slider owl-carousel">
	<?php
		$thumbnails = array();

		for ( $i = 1; $i <= $signify_number; $i++ ) {
			$content                = get_theme_mod( 'signify_testimonial_content_' . $i );
			$signify_target                 = get_theme_mod( 'signify_testimonial_target_' . $i ) ? '_blank': '_self';
			$signify_link                   = get_theme_mod( 'signify_testimonial_link_' . $i, '#' );
			$signify_title = get_theme_mod( 'signify_testimonial_title_' . $i );
			$image                  = $thumbnails[] = get_theme_mod( 'signify_testimonial_image_' . $i ) ? get_theme_mod( 'signify_testimonial_image_' . $i ) : trailingslashit( esc_url( get_template_directory_uri() ) ) . 'images/no-thumb-100x100.jpg';
			$position               = get_theme_mod( 'signify_testimonial_position_' . $i );

			if ( function_exists( 'qtrans_convertURL' ) ) {
				$signify_link = qtrans_convertURL( $signify_link );
			}

			?>

			<article id="post-<?php echo esc_attr( $i ) ?>" class="post hentry post-image has-post-thumbnail">
				<div class="hentry-inner">
					<div class="entry-container">
						<?php if ( $content ) : ?>
							<div class="entry-content">
								<?php echo wp_kses_post( $content ); ?>
							</div>
						<?php endif; ?>

						<?php if ( $signify_title || $position ) : ?>
							<header class="entry-header">
								<?php if ( $signify_title ): ?>
								<h2 class="entry-title"><a target="<?php echo esc_attr( $signify_target ); ?>" href="<?php echo esc_url( $signify_link ); ?>"><?php echo wp_kses_post( $signify_title ); ?></a></h2>
								<?php endif; ?>

								<?php if ( $position ): ?>
								<p class="entry-meta"><span class="position"><?php echo esc_html( $position ); ?></span></p>
								<?php endif; ?>
							</header>
						<?php endif; ?>
					</div><!-- .entry-container -->
				</div><!-- .hentry-inner -->
			</article>
			<?php
		}
	?>
	</div><!-- .section-content-wrapper -->

	<ul id='testimonial-dots' class='owl-dots'>
		<?php
			foreach ( $thumbnails as $thumb ) {
				echo '<li class="owl-dot"><img src="' . esc_url( $thumb ) . '"/> </li> ';
			}
		?>
	</ul>
</div>
