<?php

/**
 * Cross-sells
 *
 * Wrapper product cross-sells with swiper slider html
 *
 * @see https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/templates/cart/cross-sells.php
 * @package WooCommerce\Templates
 * @version 9.6.0
 */

defined('ABSPATH') || exit;

// Swiper options
$slider_options = htmlspecialchars(
	json_encode(
		array(
			'slidesPerView' => 2,
			'spaceBetween'  => 15,
			'itemWrapper'   => '.rt-product__thumbnail',
			'breakpoints'   => array(
				728 => array(
					'slidesPerView' => 3,
					'spaceBetween'  => 30,
				),
			),
		)
	)
);

$heading = apply_filters('woocommerce_product_upsells_products_heading', __('You may also like&hellip;', 'kubelio'));
?>
<?php if (! empty($cross_sells)) : ?>
	<div class="rt-product-cross-sells is-layout-flow">

		<?php if ($heading) : ?>
			<div class="rt-block-heading">
				<h2 class="rt-block-heading__title has-x-large-font-size"><?php echo esc_html($heading); ?></h2>
			</div>
		<?php endif; ?>

		<div class="wp-block-group">
			<div id="rt_products_cross_sells" class="rt-swiper is-swiper-pagination-outside rt-products products"
				style="--slides: 2; --gap: 30px; --slides-md: 3; --gap-md: 30px;">
				<div class="swiper js-swiper" data-options="<?php echo esc_attr($slider_options); ?>">
					<div class="swiper-wrapper">
						<?php foreach ($cross_sells as $cross_sell) : ?>
							<?php
							$post_object = get_post($cross_sell->get_id());
							setup_postdata($GLOBALS['post'] = $post_object); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited, Squiz.PHP.DisallowMultipleAssignments.Found
							?>
							<div class="swiper-slide">
								<div class="rt-swiper-item"><?php wc_get_template_part('content', 'product'); ?></div>
							</div>
						<?php endforeach; ?>
					</div>
					<div class="swiper-pagination"></div>
				</div>
				<div class="rt-swiper-navigation">
					<div class="swiper-button-prev"></div>
					<div class="swiper-button-next"></div>
				</div>
			</div>
		</div>
	</div>
<?php endif ?>

<?php wp_reset_postdata(); ?>