<?php
/**
 * Single Product Image
 *
 * @author 		WooThemes
 * @package 	WooCommerce/Templates
 * @version     3.3.2
 */

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

global $post, $woocommerce, $product;
$attachment_ids = woo_shrk_get_gallery_image_ids( $product );
$thumbnail_size = apply_filters( 'woocommerce_product_thumbnails_large_size', 'full' );
?>
<div class="images product-images <?php echo !$attachment_ids ? 'one-slide' : '' ?>">
	<div class="product-images-slider">
		<div class="swiper-wrapper">
		<?php
			if ( has_post_thumbnail() ) {
				$attachment_count = count( $attachment_ids );
				$image_title = esc_attr( get_post_field( 'post_excerpt', get_post_thumbnail_id() ) );
				$image_obj   = wp_get_attachment_image_src( get_post_thumbnail_id(), $thumbnail_size );
				$image_link  = $image_obj[0];
				$image_size  = $image_obj[1] . "x" . $image_obj[2];
				$image       = get_the_post_thumbnail( $post->ID, apply_filters( 'single_product_large_thumbnail_size', 'shop_single' ), array(
					'title' => $image_title
					) );

				if ( $attachment_count > 0 ) {
					$gallery = '[product-gallery]';
				} else {
					$gallery = '';
				}

				echo apply_filters( 
					'woocommerce_single_product_image_html', 
					sprintf( 
						'<div class="swiper-slide woocommerce-product-gallery__image"><a href="%s" itemprop="image" data-size="%s" class="woocommerce-main-image zoom" title="%s" data-rel="' . $gallery . '">%s</a></div>', 
						esc_url( $image_link ), 
						esc_attr( $image_size ), 
						esc_attr( $image_title ), 
						$image 
					), 
					$post->ID 
				);
			} else {
				echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '<div class="swiper-slide woocommerce-product-gallery__image--placeholder"><a href="%s" data-size="300x300"><img src="%s" alt="%s" /></a></div>', wc_placeholder_img_src(), wc_placeholder_img_src(), esc_html__( 'Placeholder', 'ux-shop' ) ), $post->ID );
			}

			if ( $attachment_ids ) {
				$loop = 0;
				$columns = apply_filters( 'woocommerce_product_thumbnails_columns', 3 );						
				
				foreach ( $attachment_ids as $attachment_id ) {
					$classes = array( 'zoom' );
			
					if ( $loop == 0 || $loop % $columns == 0 ) {
						$classes[] = 'first';
					}
			
					if ( ( $loop + 1 ) % $columns == 0 ) {
						$classes[] = 'last';
					}
			
					$image_title = esc_attr( get_post_field( 'post_excerpt', $attachment_id ) );
					$image_obj   = wp_get_attachment_image_src( $attachment_id, $thumbnail_size );
					$image_link  = $image_obj[0];
					$image_size  = $image_obj[1] . "x" . $image_obj[2];
					$image_class = esc_attr( implode( ' ', $classes ) );

					if ( ! $image_link ) {
						continue;
					}
					
					printf( '<div class="swiper-slide"><a href="%s" data-size="%s" title="%s">%s</a></div>', $image_link, $image_size, $image_title, wp_get_attachment_image( $attachment_id, apply_filters( 'single_product_large_thumbnail_size', 'shop_single' ) ) );
					$loop++;
				}
			}
		?>
		</div>
	<div class="prev_swipe"><i class="icon-ws-arrow-left"></i></div>
	<div class="next_swipe"><i class="icon-ws-arrow-right"></i></div>
	<div class="pagination-wrapper"><div class="pagination"></div></div>
	</div>

	<div class="thumbnails <?php echo esc_attr( 'columns-' . apply_filters( 'woocommerce_product_thumbnails_columns', 3 ) ); ?>">
	<?php do_action( 'woocommerce_product_thumbnails' ); ?>
	</div>
</div>
