<?php
/**
 * The template for displaying product content within loops
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/content-product.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://woo.com/document/template-structure/
 * @package WooCommerce\Templates
 * @version 3.6.0
 */

defined( 'ABSPATH' ) || exit;

global $product;

// Ensure visibility.
if ( empty( $product ) || ! $product->is_visible() ) {
	return;
}
?>
<li <?php wc_product_class( '', $product ); ?>>
	<!-- Single Product -->
	<div class="oa-single-product m-0">
		<!-- Product Head -->
		<div class="oa-single-product__head">
			<?php if ($product->is_on_sale()) : ?>
				<div class="p-badge"><?php esc_html_e('Sale','grshop-grocery');?></div>
			<?php endif; ?>
			<div class="oa-single-product__head">
				<a href="<?php the_permalink(); ?>"><?php echo woocommerce_get_product_thumbnail(); ?></a>
			</div>
			<!-- Button Head -->
			<div class="oa-single-product__boverlay">
				<!-- Action  Button -->
				<div class="oa-single-product__bgroup">
					<?php if (class_exists('YITH_WCQV_Frontend')) : ?>
						<a data-bs-toggle="modal" data-bs-target="#exampleModal" href="<?php the_permalink(); ?>"><i class="icofont-eye-alt"></i><span><?php esc_html_e('Quick Shop','grshop-grocery');?></span></a>
					<?php endif; ?>
					<?php if (class_exists('YITH_WCWL')) : ?>
						<a title="Wishlist" href="<?php echo esc_url(YITH_WCWL()->get_wishlist_url()); ?>"><i class="icofont-heart"></i><span><?php esc_html_e('Add to Wishlist','grshop-grocery');?></span></a>
					<?php endif; ?>
					<a title="Compare" href="<?php echo esc_url(add_query_arg('add-to-cart', $product->get_id())); ?>"><i class="icofont-random"></i><span><?php esc_html_e('Add to Compare','grshop-grocery');?></span></a>
				</div>
				<!-- Action to Cart Button -->
				<div class="oa-single-product__bgroup-2">
					<a title="Add to cart" href="<?php the_permalink(); ?>"><?php esc_html_e('View Product','grshop-grocery');?></a>
				</div>
			</div>
		</div>
		<!-- Product Content -->
		<div class="oa-single-product__content">
			<?php
			$categories = wc_get_product_category_list($product->get_id());
			if ($categories) {
				// Split the categories by commas
				$category_list = explode(',', $categories);
				// Only display the first two categories
				$category_list = array_slice($category_list, 0, 1);
				?>
				<div class="oa-single-product__cats"><?php echo implode(',', $category_list); ?></div>
			<?php } ?>
			<!-- Product Title -->
			<h3 class="oa-single-product__title">
				<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
			</h3>
			<!-- Product Price -->
			<div class="oa-single-product__price">
				<b><span><?php echo $product->get_price_html(); ?></b>
			</div>
			<!-- Rating -->
			<div class="oa-single-product__rating">
				<?php echo wc_get_rating_html($product->get_average_rating()); ?>
				<a href="<?php echo esc_url($product->get_permalink()); ?>" class="total-review"><?php esc_html_e('Revew:','grshop-grocery');?>   (<?php echo $product->get_review_count(); ?>)</a>
			</div>
			<!-- Product Button -->
			<div class="product-button">
			<?php woocommerce_template_loop_add_to_cart() ?>
			</div>
		</div>
	</div>
	<!-- End Single Product -->
</li>
