// import React from "react"; // import { useSelector } from "react-redux"; // import { Link } from "react-router-dom"; // import { selectRecentProducts } from "../../features/recentlyViewed/recentlyViewedApi"; // const RecentlyViewedCard = ({ product }) => { // const image = product.image || "/placeholder-product.png"; // const price = product.price || 0; // return ( // // {/* Image */} //
// {product.name} // {/* Soft gradient */} //
// {/* "Viewed" badge */} //
// Viewed //
//
// {/* Content */} //
//

// {product.name || "Product Name"} //

//
// ₹{price} //
//
//
// // ); // }; // const RecentlyViewed = ({ limit = 6 }) => { // const allProducts = useSelector(selectRecentProducts); // const recentProducts = allProducts.slice(0, limit); // if (recentProducts.length === 0) return null; // return ( //
//
// {/* Heading */} //
//

// Recently Viewed Products //

//

// Continue shopping from where you left off //

//
// {/* Product Grid */} //
// {recentProducts.map((product) => ( // // ))} //
//
//
// ); // }; // export default RecentlyViewed; import React from "react"; import { useSelector } from "react-redux"; import { Link } from "react-router-dom"; import { Heart } from "lucide-react"; import { selectRecentProducts } from "../../features/recentlyViewed/recentlyViewedApi"; import { useAddToWishlistMutation, useRemoveFromWishlistMutation, useGetWishlistQuery, } from "../../features/wishlist/wishlistApi"; const RecentlyViewedCard = ({ product, wishlistIds, handleWishlist }) => { const discount = product.comparePrice && product.comparePrice > product.price ? Math.round( ((product.comparePrice - product.price) / product.comparePrice) * 100, ) : 0; const offersCount = Math.floor(Math.random() * 3) + 1; // mock offers return ( {/* Image */}
{product.name} {/* Viewed Badge */}
Viewed
{/* Offers Badge */} {offersCount > 0 && (
{offersCount} OFFER{offersCount > 1 ? "S" : ""} FOR YOU
)} {/* Wishlist */}
{/* Product Info */}
{/* Brand/Category */}

{product.brand || "Brand"}

{/* Product Name */}

{product.name || "Product Name"}

{/* Price */}
₹{product.price?.toLocaleString() || "0"} {product.comparePrice && ( ₹{product.comparePrice.toLocaleString()} )} {discount > 0 && (

{discount}% OFF

)}
{/* Color Variants */} {product.variants?.length > 0 && (
{product.variants.slice(0, 5).map((variant, idx) => { const colorValue = variant.color?.toLowerCase() || "#e5e7eb"; return (
); })} {product.variants.length > 5 && ( +{product.variants.length - 5} )}
)}
); }; const RecentlyViewed = ({ limit = 6 }) => { const allProducts = useSelector(selectRecentProducts); const recentProducts = allProducts.slice(0, limit); const { data: wishlistData } = useGetWishlistQuery(); const [addToWishlist] = useAddToWishlistMutation(); const [removeFromWishlist] = useRemoveFromWishlistMutation(); const wishlistIds = wishlistData?.data?.wishlist?.map( (item) => item.product?._id || item.productId, ) || wishlistData?.data?.products?.map((item) => item._id) || []; const handleWishlist = async (e, productId) => { e.preventDefault(); e.stopPropagation(); try { if (wishlistIds.includes(productId)) { await removeFromWishlist(productId).unwrap(); } else { await addToWishlist(productId).unwrap(); } } catch (error) { console.error("Wishlist error:", error); } }; if (recentProducts.length === 0) return null; return (
{/* Heading */}

Recently Viewed Products

Continue shopping from where you left off

{/* Product Grid */}
{recentProducts.map((product) => ( ))}
); }; export default RecentlyViewed;