<?php
/**
 * Related Products
 *
 * @see         https://docs.woocommerce.com/document/template-structure/
 * @package     WooCommerce/Templates
 * @version     9.6.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
if ( $related_products ) :
	$related_layout              = apply_filters( 'multimagazine_related_products_layout', 'list' );
	$multimagazine_heading_style = multimagazine_heading_style();

	if ( 'slider' === $related_layout ) :
		$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' ) {
			$multimagazine_heading_style .= ' pagination-outside';
		}
		?>
		<div class="product-slider multi-slider <?php echo esc_attr( $multimagazine_heading_style ); ?>">
			<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 esc_html_e( 'Related products', 'multimagazine' ); ?></span></h2>
				<nav 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>
				</nav>
			</div>
			<div class="multi-slider-box splide">
				<div class="splide__track">
					<div class="splide__list">
					<?php
					foreach ( $related_products as $multimagazine_related_product ) {
						$multimagazine_post_object = get_post( $multimagazine_related_product->get_id() );

						setup_postdata( $GLOBALS['post'] =& $multimagazine_post_object ); // phpcs:ignore
						wc_get_template_part( 'content', 'product-slider-item' );
					}
					?>
					</div>
				</div>
			</div>
		</div>
		<?php
	else :
		switch ( $related_layout ) {
			case 'grid':
				$container_class = 'columns';
				break;
			case 'list':
				$container_class = 'scrolled-list scrollable-fade';
				break;
		}
		?>
		<div class="product-slider additional-post-list">
			<h2 class="spec-heading <?php echo esc_attr( $multimagazine_heading_style ); ?>"><span><?php esc_html_e( 'Related products', 'multimagazine' ); ?></span></h2>
			<ul class="<?php echo esc_attr( $container_class ); ?>">
				<?php
				foreach ( $related_products as $multimagazine_related_product ) {
					$multimagazine_post_object       = get_post( $multimagazine_related_product->get_id() );
					setup_postdata( $GLOBALS['post'] =& $multimagazine_post_object ); // phpcs:ignore
					wc_get_template_part( 'content', 'product-slider-item' );
				}
				?>
			</ul>
		</div>
	<?php endif; ?>

	<?php
endif;

wp_reset_postdata();
