);
}
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 */}
{/* 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 */}
{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"}