<?php
/**
 * The template for displaying product content in list view
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/content-product-list.php.
 *
 * @package Pawfect
 */

defined( 'ABSPATH' ) || exit;

global $product;

// Ensure visibility.
if ( empty( $product ) || ! $product->is_visible() ) {
	return;
}
?>
<div <?php wc_product_class( 'pawfect-product-item pawfect-product-list-item pawfect-group', $product ); ?>>
	<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 pawfect-flex pawfect-flex-row">

		<!-- 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 -->
		<div class="pawfect-relative pawfect-w-48 pawfect-h-48 pawfect-bg-gray-50 pawfect-overflow-hidden pawfect-flex-shrink-0">
			<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; ?>
			
			<!-- Minimal Quick Actions -->
			<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">
				<a href="<?php echo esc_url( get_permalink() ); ?>" class="pawfect-w-8 pawfect-h-8 pawfect-bg-white pawfect-rounded pawfect-flex pawfect-items-center pawfect-justify-center pawfect-shadow-sm pawfect-border pawfect-border-gray-200 pawfect-transition-colors pawfect-duration-200 hover:pawfect-bg-gray-50">
					<svg class="pawfect-w-4 pawfect-h-4 pawfect-text-gray-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
						<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"></path>
						<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"></path>
					</svg>
				</a>
			</div>
		</div>

		<!-- Product Content -->
		<div class="pawfect-p-6 pawfect-flex-1 pawfect-flex pawfect-flex-col pawfect-justify-between">
			<div>
				<!-- Product Title -->
				<h3 class="pawfect-text-lg 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 Excerpt -->
				<?php if (get_theme_mod('pawfect_shop_show_excerpt_list', false)): ?>
				<div class="pawfect-text-sm pawfect-text-gray-600 pawfect-mb-4 pawfect-line-clamp-3 product-excerpt">
					<?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; ?>

				<!-- Product Rating -->
				<?php if (wc_review_ratings_enabled()): ?>
					<div class="pawfect-flex pawfect-items-center pawfect-mb-3">
						<?php woocommerce_template_loop_rating(); ?>
					</div>
				<?php endif; ?>
			</div>

			<div class="pawfect-flex pawfect-items-center pawfect-justify-between">
				<!-- Product Price -->
				<div class="pawfect-text-primary pawfect-font-bold pawfect-text-lg">
					<?php woocommerce_template_loop_price(); ?>
				</div>

				<!-- Add to Cart Button -->
				<?php
				// Check if product is in cart for list template
				$in_cart_list = 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_list = 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-add-to-cart-btn pawfect-ajax-add-to-cart<?php echo esc_attr( $in_cart_list ? ' 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_list ? __('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>
	</div>
</div>
