<?php
/**
 * Single Product Up-Sells
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/single-product/up-sells.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @see         https://docs.woocommerce.com/document/template-structure/
 * @package     sWooCommerce/Templates
 * @version     9.6.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( $upsells ) :
	$list_layout         = apply_filters( 'multimagazine_related_products_layout', 'list' );
	$multimagazine_heading_style = multimagazine_heading_style();

	if ( 'slider' === $list_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( 'You may also like&hellip;', 'multimagazine' ); ?></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">
				<div class="splide__track">
					<div class="splide__list">
					<?php foreach ( $upsells as $multimagazine_upsell ) : ?>
						<?php
							$multimagazine_post_object = get_post( $multimagazine_upsell->get_id() );

							setup_postdata( $GLOBALS['post'] =& $multimagazine_post_object ); // phpcs:ignore
							wc_get_template_part( 'content', 'product-slider-item' );
						?>
					<?php endforeach; ?>
					</div>
				</div>
			</div>
		</div>
		<?php
	else :
		switch ( $list_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 ( $upsells as $multimagazine_up_sell ) {
					$multimagazine_post_object               = get_post( $multimagazine_up_sell->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();
