<?php
/**
 * The template for displaying product content within loops
 *
 * Template aligned with WooCommerce 9.4.0
 * @see https://woocommerce.com/document/template-structure/
 * @package Pawfect
 * @version 10.9.1
 */

defined( 'ABSPATH' ) || exit;

global $product;

// Ensure visibility.
if ( empty( $product ) || ! $product->is_visible() ) {
	return;
}

// Get the product card style from theme options
$card_style = get_theme_mod('pawfect_shop_card_style', 'modern');
?>
<li <?php wc_product_class( 'pawfect-product-item pawfect-group pawfect-shop-card-' . esc_attr($card_style), $product ); ?>>
	<?php if ($card_style === 'modern'): ?>
		<!-- Modern Product Card (Shop by Category Style) - Exact Match to Frontpage -->
		<div class="pawfect-category-card pawfect-group pawfect-relative pawfect-bg-white pawfect-rounded-2xl pawfect-shadow-sm pawfect-border pawfect-border-gray-100 pawfect-overflow-hidden pawfect-transition-all pawfect-duration-500 hover:pawfect-shadow-lg hover:pawfect-scale-[1.02]">
			
			<!-- Subtle Background Glow Effect -->


			<a href="<?php echo esc_url( get_permalink() ); ?>" class=" pawfect-relative pawfect-z-10">
				<!-- Product Image -->
				<div class="pawfect-relative pawfect-height-16 pawfect-bg-gray-100 pawfect-overflow-hidden">
					<?php echo wp_kses_post( $product->get_image('woocommerce_thumbnail', [
						'class' => 'pawfect-w-full pawfect-h-full pawfect-object-cover pawfect-transition-all pawfect-duration-700 group-hover:pawfect-scale-110'
					]) ); ?>

					<!-- Consistent Sale Badge -->
					<?php if ($product->is_on_sale()): ?>
						<span class="pawfect-absolute pawfect-top-4 pawfect-left-4 pawfect-bg-red-500 pawfect-text-white pawfect-text-xs pawfect-font-bold pawfect-px-3 pawfect-py-1 pawfect-rounded-full pawfect-shadow-lg pawfect-z-20">
							SALE
						</span>
					<?php endif; ?>

					<!-- Enhanced Quick Actions for Modern Style -->
					<?php if (get_theme_mod('pawfect_quick_view_enabled', true) || get_theme_mod('pawfect_wishlist_enabled', true)): ?>
						<div class="pawfect-absolute pawfect-top-4 pawfect-right-4 pawfect-flex pawfect-flex-col pawfect-gap-2 pawfect-opacity-0 pawfect-transition-all pawfect-duration-300 group-hover:pawfect-opacity-100 pawfect-z-20">
							<!-- Quick View Button -->
							<?php if (get_theme_mod('pawfect_quick_view_enabled', true)): ?>
								<?php echo pawfect_get_quick_view_button($product->get_id(), 'pawfect-w-10 pawfect-h-10 pawfect-bg-white pawfect-bg-opacity-90 pawfect-backdrop-blur-sm pawfect-rounded-full pawfect-flex pawfect-items-center pawfect-justify-center pawfect-shadow-lg pawfect-border pawfect-border-white pawfect-border-opacity-20 pawfect-transition-all pawfect-duration-200 hover:pawfect-bg-opacity-100 pawfect-text-gray-600 hover:pawfect-text-pawfect-primary hover:pawfect-scale-110'); ?>
							<?php endif; ?>

							<!-- Wishlist Button -->
							<?php if (get_theme_mod('pawfect_wishlist_enabled', true)): ?>
								<?php echo pawfect_get_wishlist_button($product->get_id(), 'pawfect-w-10 pawfect-h-10 pawfect-bg-white pawfect-bg-opacity-90 pawfect-backdrop-blur-sm pawfect-rounded-full pawfect-flex pawfect-items-center pawfect-justify-center pawfect-shadow-lg pawfect-border pawfect-border-white pawfect-border-opacity-20 pawfect-transition-all pawfect-duration-200 hover:pawfect-bg-opacity-100 pawfect-text-gray-600 hover:pawfect-text-red-500 hover:pawfect-scale-110'); ?>
							<?php endif; ?>
						</div>
					<?php endif; ?>

					<!-- Gradient Overlay -->
					<div class="pawfect-absolute pawfect-inset-0 pawfect-bg-gradient-to-t pawfect-from-black pawfect-from-opacity-60 pawfect-via-transparent pawfect-to-transparent"></div>

					<!-- Hover Overlay -->
					<div class="pawfect-absolute pawfect-inset-0 pawfect-bg-opacity-0 pawfect-transition-all pawfect-duration-300 group-hover:pawfect-bg-opacity-20"></div>

					<!-- Add to Cart Button -->
					<div class="pawfect-absolute pawfect-inset-0 pawfect-flex pawfect-items-center pawfect-justify-center pawfect-opacity-0 pawfect-transform pawfect-scale-75 pawfect-transition-all pawfect-duration-300 group-hover:pawfect-opacity-100 group-hover:pawfect-scale-100 pawfect-z-20">
						<?php
						// Check if product is in cart
						$in_cart = false;
						if (function_exists('WC') && WC()->cart && !WC()->cart->is_empty()) {
							foreach (WC()->cart->get_cart() as $cart_item) {
								if ($cart_item['product_id'] == $product->get_id()) {
									$in_cart = true;
									break;
								}
							}
						}
						?>
						<button type="button"
						   class="pawfect-btn pawfect-add-to-cart-btn pawfect-ajax-add-to-cart<?php echo esc_attr( $in_cart ? ' pawfect-added-to-cart' : '' ); ?>"
						   data-product-id="<?php echo esc_attr( $product->get_id() ); ?>"
						   data-product-sku="<?php echo esc_attr($product->get_sku()); ?>"
						   data-quantity="1">
							<span class="pawfect-btn-text"><?php echo esc_html( $in_cart ? __('Added to Cart', 'pawfect') : __('Add to Cart', 'pawfect') ); ?></span>
							<svg class="pawfect-w-4 pawfect-h-4 pawfect-inline-block pawfect-ml-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
								<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 3h2l.4 2M7 13h10l4-8H5.4m0 0L7 13m0 0l-2.5 5M7 13l2.5 5m0 0h8"></path>
							</svg>
						</button>
					</div>
				</div>

				<!-- Product Content -->
				<div class="pawfect-p-3">
					<h3 class="pawfect-text-lg pawfect-font-semibold pawfect-text-[#1f2937] pawfect-mb-1 pawfect-transition-colors pawfect-duration-300 group-hover:pawfect-text-pawfect-primary">
						<?php the_title(); ?>
					</h3>

					<!-- Product Excerpt for List View -->
					<?php if (get_theme_mod('pawfect_shop_show_excerpt_list', false)): ?>
					<div class="product-excerpt pawfect-text-sm pawfect-text-gray-600 pawfect-mb-2 pawfect-line-clamp-2" style="display: none;">
						<?php
						$excerpt = $product->get_short_description();
						if (empty($excerpt)) {
							$excerpt = wp_trim_words(get_the_content(), 5, '...');
						}
						echo wp_kses_post($excerpt);
						?>
					</div>
					<?php endif; ?>

					<div class="pawfect-text-pawfect-primary pawfect-font-bold pawfect-text-lg pawfect-mb-2">
						<?php echo wp_kses_post( $product->get_price_html() ); ?>
					</div>

					<!-- Arrow Icon -->
					<div class="pawfect-flex pawfect-items-center pawfect-mt-2 pawfect-text-pawfect-primary pawfect-font-medium pawfect-text-sm">
						<span class="pawfect-transition-all pawfect-duration-300 group-hover:pawfect-mr-2"><?php esc_html_e( 'View Product', 'pawfect' ); ?></span>
						<svg class="pawfect-w-4 pawfect-h-4 pawfect-ml-2 pawfect-transition-transform pawfect-duration-300 group-hover:pawfect-translate-x-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
							<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 8l4 4m0 0l-4 4m4-4H3"></path>
						</svg>
					</div>
				</div>
			</a>
		</div>
	<?php else: ?>
		<!-- Classic Product Card -->
		<div class="pawfect-feature-card pawfect-group pawfect-relative pawfect-bg-white pawfect-rounded-xl pawfect-border pawfect-border-gray-100 pawfect-transition-all pawfect-duration-300 hover:pawfect-border-gray-200 hover:pawfect-shadow-sm pawfect-overflow-hidden">

			<!-- Subtle Accent Line -->
			<div class="pawfect-absolute pawfect-top-0 pawfect-left-6 pawfect-right-6 pawfect-h-px pawfect-bg-gradient-to-r pawfect-from-transparent pawfect-via-pawfect-primary pawfect-to-transparent pawfect-opacity-0 pawfect-transition-opacity pawfect-duration-300 group-hover:pawfect-opacity-100"></div>

			<!-- Product Image Container - Classic Style -->
			<div class="pawfect-relative pawfect-height-16  pawfect-aspect-square pawfect-bg-gray-50 pawfect-overflow-hidden">
				<a href="<?php echo esc_url( get_permalink() ); ?>" class="pawfect-block">
					<?php echo wp_kses_post( $product->get_image('woocommerce_thumbnail', [
						'class' => 'pawfect-w-full pawfect-h-full pawfect-object-cover pawfect-transition-transform pawfect-duration-500 group-hover:pawfect-scale-105'
					]) ); ?>
				</a>

				<!-- Consistent Sale Badge -->
				<?php if ($product->is_on_sale()): ?>
					<span class="pawfect-absolute pawfect-top-4 pawfect-left-4 pawfect-bg-red-500 pawfect-text-white pawfect-text-xs pawfect-font-bold pawfect-px-3 pawfect-py-1 pawfect-rounded-full pawfect-shadow-lg pawfect-z-20">
						SALE
					</span>
				<?php endif; ?>

				<!-- Enhanced Quick Actions -->
				<?php if (get_theme_mod('pawfect_quick_view_enabled', true) || get_theme_mod('pawfect_wishlist_enabled', true)): ?>
					<div class="pawfect-absolute pawfect-top-3 pawfect-right-3 pawfect-flex pawfect-flex-col pawfect-gap-2 pawfect-opacity-0 pawfect-transition-all pawfect-duration-300 group-hover:pawfect-opacity-100 pawfect-z-10">
						<!-- Quick View Button -->
						<?php if (get_theme_mod('pawfect_quick_view_enabled', true)): ?>
							<?php echo pawfect_get_quick_view_button($product->get_id(), 'pawfect-w-8 pawfect-h-8 pawfect-bg-secondary pawfect-rounded-full pawfect-flex pawfect-items-center pawfect-justify-center pawfect-shadow-sm pawfect-transition-colors pawfect-duration-200 hover:pawfect-bg-primary pawfect-text-white'); ?>
						<?php endif; ?>

						<!-- Wishlist Button -->
						<?php if (get_theme_mod('pawfect_wishlist_enabled', true)): ?>
							<?php echo pawfect_get_wishlist_button($product->get_id(), 'pawfect-w-8 pawfect-h-8 pawfect-bg-secondary pawfect-rounded-full pawfect-flex pawfect-items-center pawfect-justify-center pawfect-shadow-sm pawfect-transition-colors pawfect-duration-200 hover:pawfect-bg-red-500 pawfect-text-white'); ?>
						<?php endif; ?>
					</div>
				<?php endif; ?>
			</div>

			<!-- Product Content - Classic Style -->
			<div class="pawfect-p-3">
				<!-- Product Title -->
				<h3 class="pawfect-text-base pawfect-font-semibold pawfect-mb-2 pawfect-line-clamp-2 pawfect-leading-snug">
					<a href="<?php echo esc_url( get_permalink() ); ?>" class="pawfect-transition-colors pawfect-duration-200 hover:pawfect-text-pawfect-primary">
						<?php the_title(); ?>
					</a>
				</h3>

				<!-- Product Price -->
				<div class="pawfect-text-primary pawfect-font-bold pawfect-text-sm pawfect-mb-2">
					<?php woocommerce_template_loop_price(); ?>
				</div>

				<!-- Add to Cart Button -->
				<?php
				// Check if product is in cart for classic template
				$in_cart_classic = false;
				if (function_exists('WC') && WC()->cart && !WC()->cart->is_empty()) {
					foreach (WC()->cart->get_cart() as $cart_item) {
						if ($cart_item['product_id'] == $product->get_id()) {
							$in_cart_classic = true;
							break;
						}
					}
				}
				$add_to_cart_url = $product->add_to_cart_url();
				$add_to_cart_text = $product->add_to_cart_text();
				?>
				<button type="button" class="pawfect-btn pawfect-w-full pawfect-text-center pawfect-add-to-cart-btn pawfect-ajax-add-to-cart<?php echo esc_attr( $in_cart_classic ? ' pawfect-added-to-cart' : '' ); ?>" data-product-id="<?php echo esc_attr($product->get_id()); ?>" data-product-sku="<?php echo esc_attr($product->get_sku()); ?>" data-quantity="1">
					<span class="pawfect-btn-text"><?php echo esc_html( $in_cart_classic ? __('Added to Cart', 'pawfect') : $add_to_cart_text ); ?></span>
					<svg class="pawfect-w-4 pawfect-h-4 pawfect-inline-block pawfect-ml-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
						<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 3h2l.4 2M7 13h10l4-8H5.4m0 0L7 13m0 0l-2.5 5M7 13l2.5 5m0 0h8"></path>
					</svg>
				</button>
			</div>
		</div>
	<?php endif; ?>
</li>


