<?php
/**
 * Related Products
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/single-product/related.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     WooCommerce\Templates
 * @version     3.9.0
 */

if (!defined('ABSPATH')) {
  exit;
}
$options = kaveh_get_options();
$mkshopcart = $options['kaveh_sh_cart_select'];
$heading = apply_filters('woocommerce_product_related_products_heading', __('Related products', 'kavehTheme'));
if ($related_products): ?>
  <?php if ($options['kaveh_pr_single_select'] == 'value-4'): ?>
    <?php if ($related_products): ?>
      <!-- Start Products Related -->
      <section class="detail-product-four-related">
        <div class="container position-relative">
          <!-- Start Heading -->
          <div
            class="section-heading-eight d-flex align-items-sm-center flex-wrap flex-lg-nowrap gap-4 gap-lg-0 flex-column flex-sm-row">
            <div class="text-nowrap">
              <?php if ($heading): ?>
                <div class="section-heading-eight-title">
                  <?php echo esc_html($heading); ?>
                </div>
              <?php endif; ?>
            </div>
            <a href="<?php echo get_permalink(wc_get_page_id('shop')); ?>"
              class="btn btn-purple-2 d-flex align-items-center justify-content-center text-nowrap ms-auto">
              <?php esc_html_e('View All', 'kavehTheme'); ?>
              <i class="icon-angle-circle-top-left ms-2"></i>
            </a>
            <div class="swiper-bottom end-0 d-none d-md-flex align-items-md-center ms-lg-4">
              <div
                class="swiper-detail-product-four-related-pagination swiper-pagination m-0 position-relative top-0 start-0 bottom-0 end-0 d-flex">
              </div>
              <div
                class="swiper-detail-product-four-related-button-prev swiper-button-prev m-0 w-auto h-auto position-relative top-0 start-0 bottom-0 end-0 mx-3">
              </div>
              <div
                class="swiper-detail-product-four-related-button-next swiper-button-next m-0 w-auto h-auto position-relative top-0 start-0 bottom-0 end-0">
              </div>
            </div>
          </div>
          <!-- End Heading -->
          <?php woocommerce_product_loop_start(); ?>
          <!-- Start Carousel -->
          <div class="swiper swiper-detail-product-four-related swiper-button-arrow swiper-visible">
            <div class="swiper-wrapper">
              <?php foreach ($related_products as $related_product): ?>
                <?php
                $post_object = get_post($related_product->get_id());

                setup_postdata($GLOBALS['post'] =& $post_object); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited, Squiz.PHP.DisallowMultipleAssignments.Found
                ?>
                <div class="swiper-slide">
                  <?php
                  $template_parts = array(
                    'value-1' => 'template-part/product-cart-one',
                    'value-2' => 'template-part/product-cart-two',
                    'value-3' => 'template-part/product-cart-three',
                    'value-4' => 'template-part/product-cart-four',
                    'value-5' => 'template-part/product-cart-five',
                    'value-6' => 'template-part/product-cart-six',
                    'value-7' => 'template-part/product-cart-seven',
                    'value-8' => 'template-part/product-cart-eight',
                    'value-9' => 'template-part/product-cart-nine',
                    'value-10' => 'template-part/product-cart-ten',
                    'value-11' => 'template-part/product-cart-eleven',
                    'value-12' => 'template-part/product-cart-twelve',
                    'value-13' => 'template-part/product-cart-thirteen',
                    'value-14' => 'template-part/product-cart-fourteen',
                    'value-15' => 'template-part/product-cart-fifteen',
                    'value-16' => 'template-part/product-cart-sixteen',
                    'value-18' => 'template-part/product-cart-eighteen',
                  );
                  if (array_key_exists($mkshopcart, $template_parts)) {
                    get_template_part($template_parts[$mkshopcart]);
                  }
                  ?>
                </div>

              <?php endforeach; ?>

            </div>
            <div
              class="swiper-bottom position-absolute w-100 start-0 bottom-0 end-0 mx-auto d-flex d-md-none align-items-center justify-content-center">
              <div class="swiper-pagination swiper-pagination m-0 position-relative top-0 start-0 bottom-0 end-0 d-flex">
              </div>
              <div
                class="swiper-button-prev swiper-button-prev m-0 w-auto h-auto position-relative top-0 start-0 bottom-0 end-0 mx-3">
              </div>
              <div
                class="swiper-button-next swiper-button-next m-0 w-auto h-auto position-relative top-0 start-0 bottom-0 end-0">
              </div>
            </div>

          </div>
          <!-- End Carousel -->
          <?php woocommerce_product_loop_end(); ?>
          <?php wp_reset_postdata(); ?>
        </div>
      </section>
      <!-- End Products Related -->
    <?php endif; ?>
  <?php else: ?>
    <?php if ($related_products): ?>
      <!-- Start Products Related -->
      <section class="detail-product-four-related">
        <div class="container position-relative">
          <!-- Start Heading -->
          <div
            class="section-heading-eight d-flex align-items-sm-center flex-wrap flex-lg-nowrap gap-4 gap-lg-0 flex-column flex-sm-row">
            <div class="text-nowrap">
              <?php if ($heading): ?>
                <div class="section-heading-eight-title">
                  <?php echo esc_html($heading); ?>
                </div>
              <?php endif; ?>
            </div>
            <a href="<?php echo get_permalink(wc_get_page_id('shop')); ?>"
              class="btn btn-purple-2 d-flex align-items-center justify-content-center text-nowrap ms-auto">
              <?php esc_html_e('View All', 'kavehTheme'); ?>
              <i class="icon-angle-circle-top-left ms-2"></i>
            </a>
            <div class="swiper-bottom end-0 d-none d-md-flex align-items-md-center ms-lg-4">
              <div
                class="swiper-detail-product-four-related-pagination swiper-pagination m-0 position-relative top-0 start-0 bottom-0 end-0 d-flex">
              </div>
              <div
                class="swiper-detail-product-four-related-button-prev swiper-button-prev m-0 w-auto h-auto position-relative top-0 start-0 bottom-0 end-0 mx-3">
              </div>
              <div
                class="swiper-detail-product-four-related-button-next swiper-button-next m-0 w-auto h-auto position-relative top-0 start-0 bottom-0 end-0">
              </div>
            </div>
          </div>
          <!-- End Heading -->
          <?php woocommerce_product_loop_start(); ?>
          <!-- Start Carousel -->
          <div class="swiper swiper-detail-product-four-related swiper-button-arrow swiper-visible">
            <div class="swiper-wrapper">
              <?php foreach ($related_products as $related_product): ?>
                <?php
                $post_object = get_post($related_product->get_id());

                setup_postdata($GLOBALS['post'] =& $post_object); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited, Squiz.PHP.DisallowMultipleAssignments.Found
                ?>
                <div class="swiper-slide">
                  <?php
                  $template_parts = array(
                    'value-1' => 'template-part/product-cart-one',
                    'value-2' => 'template-part/product-cart-two',
                    'value-3' => 'template-part/product-cart-three',
                    'value-4' => 'template-part/product-cart-four',
                    'value-5' => 'template-part/product-cart-five',
                    'value-6' => 'template-part/product-cart-six',
                    'value-7' => 'template-part/product-cart-seven',
                    'value-8' => 'template-part/product-cart-eight',
                    'value-9' => 'template-part/product-cart-nine',
                    'value-10' => 'template-part/product-cart-ten',
                    'value-11' => 'template-part/product-cart-eleven',
                    'value-12' => 'template-part/product-cart-twelve',
                    'value-13' => 'template-part/product-cart-thirteen',
                    'value-14' => 'template-part/product-cart-fourteen',
                    'value-15' => 'template-part/product-cart-fifteen',
                    'value-16' => 'template-part/product-cart-sixteen',
                    'value-18' => 'template-part/product-cart-eighteen',
                  );
                  if (array_key_exists($mkshopcart, $template_parts)) {
                    get_template_part($template_parts[$mkshopcart]);
                  }
                  ?>
                </div>

              <?php endforeach; ?>

            </div>
            <div
              class="swiper-bottom position-absolute w-100 start-0 bottom-0 end-0 mx-auto d-flex d-md-none align-items-center justify-content-center">
              <div class="swiper-pagination swiper-pagination m-0 position-relative top-0 start-0 bottom-0 end-0 d-flex">
              </div>
              <div
                class="swiper-button-prev swiper-button-prev m-0 w-auto h-auto position-relative top-0 start-0 bottom-0 end-0 mx-3">
              </div>
              <div
                class="swiper-button-next swiper-button-next m-0 w-auto h-auto position-relative top-0 start-0 bottom-0 end-0">
              </div>
            </div>

          </div>
          <!-- End Carousel -->
          <?php woocommerce_product_loop_end(); ?>
          <?php wp_reset_postdata(); ?>
        </div>
      </section>
      <!-- End Products Related -->
    <?php endif; ?>
    <?php
  endif;

  wp_reset_postdata();


endif;


