"use client"; import { memo, useState, useCallback } from "react"; import { Plus, Minus } from "lucide-react"; import CardStack from "@/components/cardStack/CardStack"; import ProductImage from "@/components/shared/ProductImage"; import QuantityButton from "@/components/shared/QuantityButton"; import Button from "@/components/button/Button"; import { useTheme } from "@/providers/themeProvider/ThemeProvider"; import { useProducts } from "@/hooks/useProducts"; import { getButtonProps } from "@/lib/buttonUtils"; import { cls, shouldUseInvertedText } from "@/lib/utils"; import type { Product } from "@/lib/api/product"; import type { LucideIcon } from "lucide-react"; import type { ButtonConfig, GridVariant, CardAnimationType, TitleSegment } from "@/components/cardStack/types"; import type { CTAButtonVariant, ButtonPropsForVariant } from "@/components/button/types"; import type { TextboxLayout, InvertedBackground } from "@/providers/themeProvider/config/constants"; type ProductCardThreeGridVariant = Exclude; type ProductCard = Product & { onQuantityChange?: (quantity: number) => void; initialQuantity?: number; priceButtonProps?: Partial>; }; interface ProductCardThreeProps { products?: ProductCard[]; carouselMode?: "auto" | "buttons"; gridVariant: ProductCardThreeGridVariant; uniformGridCustomHeightClasses?: string; animationType: CardAnimationType; title: string; titleSegments?: TitleSegment[]; description: string; tag?: string; tagIcon?: LucideIcon; buttons?: ButtonConfig[]; textboxLayout: TextboxLayout; useInvertedBackground: InvertedBackground; ariaLabel?: string; className?: string; containerClassName?: string; cardClassName?: string; imageClassName?: string; textBoxTitleClassName?: string; textBoxTitleImageWrapperClassName?: string; textBoxTitleImageClassName?: string; textBoxDescriptionClassName?: string; cardNameClassName?: string; quantityControlsClassName?: string; gridClassName?: string; carouselClassName?: string; controlsClassName?: string; textBoxClassName?: string; textBoxTagClassName?: string; textBoxButtonContainerClassName?: string; textBoxButtonClassName?: string; textBoxButtonTextClassName?: string; } interface ProductCardItemProps { product: ProductCard; shouldUseLightText: boolean; cardClassName?: string; imageClassName?: string; cardNameClassName?: string; quantityControlsClassName?: string; } const ProductCardItem = memo(({ product, shouldUseLightText, cardClassName = "", imageClassName = "", cardNameClassName = "", quantityControlsClassName = "", }: ProductCardItemProps) => { const theme = useTheme(); const [quantity, setQuantity] = useState(product.initialQuantity || 1); const handleIncrement = useCallback((e: React.MouseEvent) => { e.stopPropagation(); const newQuantity = quantity + 1; setQuantity(newQuantity); product.onQuantityChange?.(newQuantity); }, [quantity, product]); const handleDecrement = useCallback((e: React.MouseEvent) => { e.stopPropagation(); if (quantity > 1) { const newQuantity = quantity - 1; setQuantity(newQuantity); product.onQuantityChange?.(newQuantity); } }, [quantity, product]); return (

{product.name}

{quantity}
); }); ProductCardItem.displayName = "ProductCardItem"; const ProductCardThree = ({ products: productsProp, carouselMode = "buttons", gridVariant, uniformGridCustomHeightClasses = "min-h-95 2xl:min-h-105", animationType, title, titleSegments, description, tag, tagIcon, buttons, textboxLayout, useInvertedBackground, ariaLabel = "Product section", className = "", containerClassName = "", cardClassName = "", imageClassName = "", textBoxTitleClassName = "", textBoxTitleImageWrapperClassName = "", textBoxTitleImageClassName = "", textBoxDescriptionClassName = "", cardNameClassName = "", quantityControlsClassName = "", gridClassName = "", carouselClassName = "", controlsClassName = "", textBoxClassName = "", textBoxTagClassName = "", textBoxButtonContainerClassName = "", textBoxButtonClassName = "", textBoxButtonTextClassName = "", }: ProductCardThreeProps) => { const theme = useTheme(); const { products: fetchedProducts, isLoading } = useProducts(); const products = (fetchedProducts.length > 0 ? fetchedProducts : productsProp) as ProductCard[]; const shouldUseLightText = shouldUseInvertedText(useInvertedBackground, theme.cardStyle); if (isLoading && !productsProp) { return (

Loading products...

); } return ( {products.map((product, index) => ( ))} ); }; ProductCardThree.displayName = "ProductCardThree"; export default ProductCardThree;