<?php
	global $product;
	global $campoal_options;
	
	// Ensure visibility
	if ( ! $product || ! $product->is_visible() ) {
		return;
	}
	
	$class = ( $product->is_on_sale() ) ? ' sale' : false;
	$add_cart_button = isset($campoal_options['conikal_add_cart_style_field']) ? $campoal_options['conikal_add_cart_style_field'] : 'text';
	$external_link = isset($campoal_options['conikal_external_link_field']) ? $campoal_options['conikal_external_link_field'] : 0;
?>
	<div class="ui fluid card product-card<?php echo esc_attr($class); ?>">
		<?php if(has_post_thumbnail()) : ?>
			<a href="<?php the_permalink(); ?>" class="image" target="<?php echo esc_attr($external_link != 0 ? '_blank' : '_self') ?>" <?php echo esc_attr($external_link != 0 ? '' : 'data-bjax') ?>>
				<div class="product-rating">
					<?php get_template_part('woocommerce/content-product', 'rating'); ?>
				</div>
				<?php if ($product->is_on_sale()){ ?>
				<div class="ui primary ribbon label sale-label">
			        <?php esc_html_e('SALE!', 'campoal') ?>
			    </div>
				<?php } ?>
				<div class="ui dimmer">
	                <div class="content">
	                    <div class="center">
	                        <div class="ui icon inverted circular big button"><i class="external alternate icon"></i></div>
	                    </div>
	                </div>
	            </div>
				<?php echo woocommerce_get_product_thumbnail('woocommerce_thumbnail'); ?>
			</a>
		<?php endif; ?>

		<div class="content product-content">
			<div class="header card-product-title">
				<a href="<?php the_permalink(); ?>" data-bjax><?php the_title(); ?></a>
			</div>
			<div class="description">
				<p><?php get_template_part('woocommerce/content-product', 'excerpt'); ?></p>
				<div class="product-price<?php echo esc_attr($add_cart_button != 'not' ? '' : ' not-button') ?>">
					<?php woocommerce_template_loop_price(); ?>
				</div>
			</div>
		</div>
		<?php if ($add_cart_button != 'not') { ?>
			<div class="extra content">
			<?php echo woocommerce_template_loop_add_to_cart(); ?>
			</div>
		<?php } ?>
	</div>
