"use client" import { useState } from "react" import Image from "next/image" import Link from "next/link" import { Minus, Plus, Heart, ShoppingCart, Store } from "lucide-react" import { Button } from "@/components/ui/button" import { Card } from "@/components/ui/card" import { Separator } from "@/components/ui/separator" import { Badge } from "@/components/ui/badge" import { Avatar, AvatarFallback } from "@/components/ui/avatar" import placeholder from "@/public/jb.webp" import { useProduct, useCategories } from "@/lib/hooks" import { Skeleton } from "@/components/ui/skeleton" interface ProductDetailProps { slug: string } const ProductPageContent = ({ slug }: ProductDetailProps) => { const [isClient, setIsClient] = useState(false) const [selectedImage, setSelectedImage] = useState(0) const [quantity, setQuantity] = useState(1) const [isFavorite, setIsFavorite] = useState(false) const [isInCart, setIsInCart] = useState(false) const [isLoading, setIsLoading] = useState(false) const { data: product, isLoading: productLoading, error } = useProduct(slug) const { data: categoriesData } = useCategories() if (!isClient) { typeof window !== "undefined" && setIsClient(true) } const t = { addToCart: "Add to Cart", goToCart: "Go to Cart", price: "Price:", aboutProduct: "About Product", brand: "Brand", model: "Model", description: "Product Description", recommended: "Recommended Products", store: "Store", writeToStore: "Write to Store", color: "Color:", } const handleAddToCart = async () => { setIsLoading(true) try { // TODO: implement cart API call await new Promise((resolve) => setTimeout(resolve, 500)) setIsInCart(true) } finally { setIsLoading(false) } } const handleQuantityChange = async (newQuantity: number) => { if (newQuantity < 1) return setIsLoading(true) try { setQuantity(newQuantity) // TODO: implement cart quantity update API call await new Promise((resolve) => setTimeout(resolve, 300)) } finally { setIsLoading(false) } } const handleToggleFavorite = () => { setIsFavorite(!isFavorite) // TODO: implement favorites API call } if (productLoading) { return (
{[1, 2, 3].map((i) => ( ))}
) } if (error || !product) { return (

Product not found

) } return (
{/* Product Images */}
{product.labels && product.labels.length > 0 && (
{product.labels.map((label) => ( {label.text} ))}
)} {product.name}
{/* Thumbnail Images */} {product.images && product.images.length > 1 && (
{product.images.map((image, index) => ( ))}
)}
{/* Product Info */}

{product.name}

{product.category && (
Category: {product.category}
)}
{/* Product Info Table */}

{t.aboutProduct}

{product.brand && ( <>
{t.brand} {product.brand}
)} {product.stock !== undefined && ( <>
Stock {product.stock}
)}
{/* Description */} {product.description && (

{t.description}

{product.description}

)}
{/* Price & Actions Sidebar */}
{t.price} ${product.price}
{isInCart ? (
{quantity}
) : ( )}
{/* Seller Card */}

{t.store}

Official Store

) } export default ProductPageContent