"use client"; import { useState, useEffect } from "react"; import Image from "next/image"; import Link from "next/link"; import { motion, AnimatePresence } from "framer-motion"; import { ChevronDown, Star, Minus, Plus } from "lucide-react"; import type { Product } from "@/types/saleor"; import { useSaleorCheckoutStore } from "@/stores/saleorCheckoutStore"; import { getProductPrice, getProductPriceAmount, getLocalizedProduct, formatPrice } from "@/lib/saleor"; import ProductCard from "@/components/product/ProductCard"; import ProductBenefits from "@/components/product/ProductBenefits"; import ProductReviews from "@/components/product/ProductReviews"; import AsSeenIn from "@/components/home/AsSeenIn"; import TrustBadges from "@/components/home/TrustBadges"; import BeforeAfterGallery from "@/components/home/BeforeAfterGallery"; import HowItWorks from "@/components/home/HowItWorks"; import NewsletterSection from "@/components/home/NewsletterSection"; interface ProductDetailProps { product: Product; relatedProducts: Product[]; locale?: string; } // Expandable Section Component function ExpandableSection({ title, children, defaultOpen = false }: { title: string; children: React.ReactNode; defaultOpen?: boolean; }) { const [isOpen, setIsOpen] = useState(defaultOpen); return (
{isOpen && (
{children}
)}
); } // Star Rating Component function StarRating({ rating = 5, count = 0 }: { rating?: number; count?: number }) { return (
{[...Array(5)].map((_, i) => ( ))}
{count > 0 && ( ({count >= 1000 ? '1000+' : count}) )}
); } export default function ProductDetail({ product, relatedProducts, locale = "SR" }: ProductDetailProps) { const [selectedImage, setSelectedImage] = useState(0); const [quantity, setQuantity] = useState(1); const [isAdding, setIsAdding] = useState(false); const [urgencyIndex, setUrgencyIndex] = useState(0); const { addLine, openCart } = useSaleorCheckoutStore(); // Cycle through urgency messages useEffect(() => { const interval = setInterval(() => { setUrgencyIndex(prev => (prev + 1) % 3); }, 3000); return () => clearInterval(interval); }, []); const urgencyMessages = [ { icon: "🚀", text: "Hurry up! 500+ items sold in the last 3 days!" }, { icon: "🛒", text: "In the carts of 2.5K people - buy before its gone!" }, { icon: "👀", text: "7,562 people viewed this product in the last 24 hours!" }, ]; const localized = getLocalizedProduct(product, locale); const variant = product.variants?.[0]; // Get all images from media const images = product.media?.length > 0 ? product.media.filter(m => m.type === "IMAGE") : [{ id: "0", url: "/placeholder-product.jpg", alt: localized.name, type: "IMAGE" as const }]; const handleAddToCart = async () => { if (!variant?.id) return; setIsAdding(true); try { await addLine(variant.id, quantity); openCart(); } finally { setIsAdding(false); } }; const isAvailable = variant?.quantityAvailable > 0; const price = getProductPrice(product); const priceAmount = getProductPriceAmount(product); const originalPrice = priceAmount > 0 ? formatPrice(Math.round(priceAmount * 1.30)) : null; // Extract short description (first sentence or first 100 chars) const shortDescription = localized.description ? localized.description.split('.')[0] + '.' : locale === "EN" ? "Premium natural oil for your beauty routine." : "Premium prirodno ulje za vašu rutinu lepote."; // Parse benefits from product metadata or use defaults const benefits = product.metadata?.find(m => m.key === "benefits")?.value?.split(',') || [ locale === "EN" ? "Natural" : "Prirodno", locale === "EN" ? "Organic" : "Organsko", locale === "EN" ? "Cruelty-free" : "Bez okrutnosti", ]; return ( <>
{/* Breadcrumb - with proper top padding for fixed header */}
{/* Product Content */}
{/* Image Gallery - Left Side */} {/* Thumbnails - Vertical on Desktop, Hidden on Mobile */} {images.length > 1 && (
{images.map((image, index) => ( ))}
)} {/* Main Image */}
{images[selectedImage].alt {/* Carousel Navigation - Mobile Only */} {images.length > 1 && ( <> {/* Left Arrow */} {/* Right Arrow */} {/* Dot Indicators - Mobile Only */}
{images.map((_, index) => (
)}
{/* Product Info - Right Side */} {/* Urgency Sales Banner */} {urgencyMessages[urgencyIndex].icon} {urgencyMessages[urgencyIndex].text} {/* Product Name */}

{localized.name}

{/* Short Description */}

{shortDescription}

{/* Stock Warning - Static */}
Stocks are running out!
{/* Discount Price Display */} {originalPrice && priceAmount > 0 && (
{originalPrice} -30%
{price}
)} {/* Price & Rating */} {!originalPrice && (
{price || (locale === "EN" ? "Contact for price" : "Kontaktirajte za cenu")}
)} {/* Divider */}
{/* Size Selector */} {product.variants && product.variants.length > 1 && (
{locale === "EN" ? "Size" : "Veličina"}
{product.variants.map((v) => ( ))}
)} {/* Quantity */}
{locale === "EN" ? "Qty" : "Kol"}
{quantity}
{/* Add to Cart Button - Action verb + value */} {isAvailable ? ( ) : (
{locale === "EN" ? "Out of Stock" : "Nema na stanju"}
)} {/* Free Shipping Note - with urgency */}

{locale === "EN" ? "Free shipping on orders over 3,000 RSD" : "Besplatna dostava za porudžbine preko 3.000 RSD"}

{/* Trust Indicators */}

{locale === "EN" ? "30-Day Guarantee" : "30-dnevna garancija"}

{locale === "EN" ? "Secure Checkout" : "Sigurno plaćanje"}

{locale === "EN" ? "Easy Returns" : "Lak povrat"}

{/* Divider */}
{/* Benefits */}
{locale === "EN" ? "Benefits" : "Prednosti"}
{benefits.map((benefit, index) => ( {benefit.trim()} ))}
{/* Expandable Sections */}

{locale === "EN" ? "Apply a small amount to clean, damp hair or skin. Massage gently until absorbed. Use daily for best results." : "Nanesite malu količinu na čistu, vlažnu kosu ili kožu. Nežno masirajte dok se ne upije. Koristite svakodnevno za najbolje rezultate." }

{locale === "EN" ? "100% Pure Natural Oil. No additives, preservatives, or artificial fragrances." : "100% čisto prirodno ulje. Bez dodataka, konzervansa ili veštačkih mirisa." }

{/* SKU */} {variant?.sku && (

SKU: {variant.sku}

)}
{/* Customer Reviews */} {/* As Featured In - Full Width */} {/* Before/After Gallery */} {/* Related Products */} {relatedProducts && relatedProducts.length > 0 && (
{locale === "EN" ? "You May Also Like" : "Možda će vam se svideti"}

{locale === "EN" ? "Similar Products" : "Slični proizvodi"}

{relatedProducts.filter(p => p && p.id).slice(0, 4).map((relatedProduct, index) => (
))}
)} {/* Product Benefits */} {/* Trust Badges */} {/* How It Works */} {/* Newsletter */} ); }