"use client"; import { useState } from "react"; import Image from "next/image"; import { motion } from "framer-motion"; import type { Product } from "@/types/saleor"; import { useSaleorCheckoutStore } from "@/stores/saleorCheckoutStore"; import { getProductPrice, getProductImage, getLocalizedProduct } from "@/lib/saleor"; import ProductCard from "@/components/product/ProductCard"; interface ProductDetailProps { product: Product; relatedProducts: Product[]; locale?: string; } 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 { addLine, openCart } = useSaleorCheckoutStore(); const localized = getLocalizedProduct(product, locale); const variant = product.variants?.[0]; const images = product.media?.length > 0 ? product.media : [{ id: "0", url: "/placeholder-product.jpg", alt: localized.name, type: "IMAGE" }]; const handleAddToCart = async () => { if (!variant?.id) return; setIsAdding(true); try { await addLine(variant.id, quantity); openCart(); } finally { setIsAdding(false); } }; const stripHtml = (html: string) => { if (!html) return ""; return html.replace(/<[^>]*>/g, ""); }; const isAvailable = variant?.quantityAvailable > 0; const price = getProductPrice(product); return ( <>
{/* Product Images */}
{images[selectedImage] && ( {images[selectedImage].alt )}
{images.length > 1 && (
{images.map((image, index) => ( ))}
)}
{/* Product Info */}

{localized.name}

{price || (locale === "EN" ? "Contact for price" : "Kontaktirajte za cenu")}

{/* Short Description */}

{stripHtml(localized.description).slice(0, 200)}...

{/* Add to Cart */} {isAvailable ? (
{/* Quantity Selector */}
{quantity}
{/* Add to Cart Button */}
) : (
{locale === "EN" ? "Out of Stock" : "Nema na stanju"}
)} {/* SKU */} {variant?.sku && (

SKU: {variant.sku}

)} {/* Full Description */} {localized.description && (

{locale === "EN" ? "Description" : "Opis"}

)}
{/* Related Products */} {relatedProducts.length > 0 && (

{locale === "EN" ? "You May Also Like" : "Možda će vam se svideti"}

{relatedProducts.map((relatedProduct, index) => ( ))}
)} ); }