<?php

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

global $product, $yith_wcwl, $product_slide_size;

$attachment_ids = $product->get_gallery_attachment_ids();
$count_attachments = count($attachment_ids);

if ( !$product_slide_size ) {
	$product_slide_size = 2;
}

?>

<div class="preview hidden-tablet hidden-phone <?php if ( $product_slide_size < 3 ) { echo 'small'; } ?>" style="display: none;">
	<div class="wrapper">

		<?php if ( $count_attachments > 1 ) { ?>
			<div class="col-1">

				<?php

				$preview_limit = 3; // TODO: make it configurable from admin panel

				$thumbImageWidth = etheme_get_option('single_product_thumb_width', 63);
				$thumbImageHeight = etheme_get_option('single_product_thumb_height', 90);
				$thumbImageCrop = false;

				?>
				<?php for ( $i=0; $i < $preview_limit; $i++ ) {

					if ( !isset($attachment_ids[$i]) || !$attachment_ids[$i] ) {
						continue;
					}

					$big_link = wp_get_attachment_url( $attachment_ids[$i] );
					$image_link = etheme_get_image($attachment_ids[$i], $thumbImageWidth, $thumbImageHeight, $thumbImageCrop);

					?>

					<a class="image" data-rel="<?php echo $big_link; ?>" href="#">
						<img class="thumb" alt="" src="<?php echo $image_link; ?>" />
					</a>

				<?php } //endfor; ?>

			</div>
		<?php } //endif; ?>
		<div class="col-2<?php if ( $count_attachments > 1 ) { echo ' with_media'; } ?>">
			<div class="big_image">
				<?php etheme_wc_product_labels(); ?>
				<a href="<?php the_permalink(); ?>">

					<?php if ( has_post_thumbnail() ) {
						echo get_the_post_thumbnail( $post->ID, 'shop_single' );
					} else { ?>
						<?php if ( $attachment_ids ) { ?>
							<img alt="" src="<?php echo wp_get_attachment_url($attachment_ids[0]); ?>" />
						<?php } else {
							echo woocommerce_placeholder_img( 'shop_single' );
						} //endif; ?>
					<?php } //endif; ?>
				</a>
			</div>

			<?php if ( etheme_get_option('quick_view') ) { ?>
				<a class="quickview img-circle hidden-phone hidden-small-desktop hidden-tablet" data-product-id="<?php echo $product->id; ?>"><?php _e( 'Quick View', 'woocommerce' ); ?></a>
			<?php } ?>

			<div class="wrapper-hover">
				<div class="product-name">
					<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
				</div>
				<div class="wrapper">
					<?php do_action('etheme_after_shop_loop_item_title'); ?>

				</div>
				<div class="clearfix"></div>

				<?php if( class_exists( 'YITH_WCWL' ) ) { ?>
					<div class="product-link">
						<a class="wft_add_to_wishlist" href="<?php echo esc_url( $yith_wcwl->get_addtowishlist_url() ); ?>" data-product-id="<?php echo $product->id; ?>" data-product-type="<?php echo $product->product_type; ?>"><?php _e('Add to Wishlist', 'buyshop'); ?></a>
					</div>
				<?php } //endif; ?>
			</div>
		</div>
	</div>
</div>