<?php
/**
 * Post slider rendering
 *
 * @package Multi
 */

if ( ! defined( 'ABSPATH' ) ) {
	die;
}
/**
 * Renders posts slider
 *
 * @param array  $queries Array of WP_Query objects.
 * @param string $title Slider title text.
 * @param string $classes CSS classes to apply to the slider.
 */
function multimagazine_post_slider( $queries, $title, $classes ) {
	$multimagazine_gutter = intval( get_theme_mod( 'multi_column_gap', MULTIMAGAZINE_COLUMN_GAP ) ) / 2;
	if ( get_theme_mod( 'pagination_dot_border_position', MULTIMAGAZINE_PAGINATION_DOT_BORDER_POSITION ) === 'outside' ) {
		$classes .= ' pagination-outside';
	}

	?>
	<div class="multi-slider <?php echo esc_attr( $classes ); ?>">
		<div class="multi-slider-header <?php echo esc_attr( multimagazine_heading_style() ); ?>">
			<h2 class="multi-slider-title spec-heading <?php echo esc_attr( multimagazine_heading_style() ); ?>"><span><?php echo esc_html( $title ); ?></span></h2>
			<p class="multi-slider-controls">
				<a href="#" class="multi-slider-arrow prev" title="<?php esc_attr_e( 'Previous', 'multimagazine' ); ?>" aria-label="<?php esc_attr_e( 'Previous', 'multimagazine' ); ?>"><i class="m-icon m-icon-arrow-circle-left" aria-hidden="true"></i></a>
				<a href="#" class="multi-slider-arrow next" title="<?php esc_attr_e( 'Next', 'multimagazine' ); ?>" aria-label="<?php esc_attr_e( 'Next', 'multimagazine' ); ?>"><i class="m-icon m-icon-arrow-circle-right" aria-hidden="true"></i></a>
			</p>
		</div>
		<div class="multi-slider-box splide" data-gutter="<?php echo esc_attr( $multimagazine_gutter ); ?>">
			<?php
			foreach ( $queries as $query ) :
				if ( ! empty( $query ) && $query->have_posts() ) :
					?>
					<div class="splide__track">
						<div class="splide__list">
					<?php
					while ( $query->have_posts() ) :
						$post = $query->the_post();
						?>
						<article class="slide splide__slide">
						<?php if ( has_post_thumbnail() ) : ?>
							<div class="img"><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( 'multimagazine-thumbnail-slider' ); ?></a></div>
						<?php endif; ?>
							<h3 class="post-title"><a href="<?php the_permalink(); ?>"><?php multimagazine_the_title(); ?></a></h3>
						<?php if ( ! has_post_thumbnail() ) : ?>
							<p><?php echo wp_kses_post( multimagazine_custom_excerpt( 15, $post ) ); ?></p>
						<?php endif; ?>
						</article>
						<?php
					endwhile;
					?>
						</div>
					</div>
					<?php
				endif;
			endforeach;
			?>
		</div>
	</div>
	<?php
}
