import ProductCard from './ProductCard'; import { useRef } from 'react'; import { ChevronLeft, ChevronRight, ArrowRight } from 'lucide-react'; import { useTranslation } from 'react-i18next'; import { Link } from 'react-router-dom'; import { getLocalizedField } from '../utils/localization'; import { getSectionPaddingClasses } from '../utils/spacing'; interface DynamicProductCarouselProps { payload: any; } export default function DynamicProductCarousel({ payload }: DynamicProductCarouselProps) { const { i18n } = useTranslation(); const lang = i18n.language; const p = payload || {}; const { products = [] } = p; const title = getLocalizedField(p.title, lang); const description = getLocalizedField(p.description, lang); const cardStyle = p.cardStyle || 'standard'; const isMinimal = cardStyle === 'minimal' || cardStyle === 'swatch' || cardStyle === 'minimal_swatch'; const viewAllLink = p.viewAllLink || '/products'; const viewAllText = getLocalizedField(p.viewAllText, lang) || 'View All'; const badgeText = getLocalizedField(p.badgeText, lang); const layout = p.layout || 'carousel'; const containerWidth = p.containerWidth || 'standard'; const cardSize = p.cardSize || 'medium'; const getContainerWidthClass = (width: string) => { switch (width) { case 'full': return 'w-full max-w-none'; case 'wide': return 'w-full max-w-[1600px] mx-auto'; case 'standard': default: return 'ui-section-inner'; } }; const getCarouselCardWidth = () => { switch (cardSize) { case 'compact': return 'w-[46vw] sm:w-[calc((100%-32px)/3)] md:w-[calc((100%-60px)/4)] lg:w-[calc((100%-100px)/6)] flex-none snap-start'; case 'large': return 'w-[78vw] sm:w-[calc((100%-16px)/2)] md:w-[calc((100%-20px)/2)] lg:w-[calc((100%-40px)/3)] flex-none snap-start'; case 'medium': default: return 'w-[68vw] sm:w-[calc((100%-16px)/2)] md:w-[calc((100%-40px)/3)] lg:w-[calc((100%-60px)/4)] flex-none snap-start'; } }; const getGridColsClass = () => { switch (cardSize) { case 'compact': return 'grid grid-cols-2 gap-3 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-6'; case 'large': return 'grid grid-cols-1 gap-6 sm:grid-cols-2 md:grid-cols-3'; case 'medium': default: return 'grid grid-cols-2 gap-4 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4'; } }; const carouselRef = useRef(null); const scrollLeft = () => carouselRef.current?.scrollBy({ left: -300, behavior: 'smooth' }); const scrollRight = () => carouselRef.current?.scrollBy({ left: 300, behavior: 'smooth' }); return (
{isMinimal ? (
{title &&

{title}

} {description &&

{description}

}
{viewAllText}
) : ( (title || description) && (
{title &&

{title}

} {description &&

{description}

}
) )} {products.length === 0 ? (
No products to display.
) : layout === 'grid' ? (
{products.map((prod: any) => ( ))}
) : (
{products.map((prod: any) => (
))}
)}
); }