'use client'; import { useState } from 'react'; import { v4 as uuid } from 'uuid'; import ProductMockup from './ProductMockup'; import Price from './Price'; import LoginPromptModal from './LoginPromptModal'; import AddToCartModal from './AddToCartModal'; import { useCart } from '@/lib/cartStore'; import { getColorName } from '@/lib/colorNames'; import { checkCustomerAuth } from '@/app/actions'; import type { ProductDTO } from '@/lib/types'; export default function StandardProductView({ product }: { product: ProductDTO }) { const [color, setColor] = useState(product.colors[0]); const [size, setSize] = useState(product.sizes[0] ?? null); const [view, setView] = useState<'front' | 'back'>('front'); const [quantity, setQuantity] = useState(1); const [justAdded, setJustAdded] = useState(false); const [showLoginPrompt, setShowLoginPrompt] = useState(false); const [showAddToCartModal, setShowAddToCartModal] = useState(false); const addItem = useCart((s) => s.addItem); const hasBack = Boolean(product.imageUrlBack); function renderPhoto(v: 'front' | 'back') { const colorPhoto = v === 'front' ? product.colorPhotos[color] : product.colorPhotosBack[color]; if (colorPhoto) { return {`${product.name}; } const activePhoto = v === 'front' ? product.imageUrl : product.imageUrlBack; if (!activePhoto) { return ; } if (product.photoRecolorable) { return (
{product.name}
); } return {product.name}; } const handleAddToBag = async () => { addItem({ cartItemId: uuid(), productId: product.id, slug: product.slug, name: product.name, mockup: product.mockup, color, size, quantity, unitPrice: product.effectivePrice, designJson: { front: [], back: [] }, designPreviewUrl: product.colorPhotos[color] ?? product.imageUrl ?? '', designPreviewUrlBack: product.colorPhotosBack[color] ?? product.imageUrlBack ?? null, placementPreviewUrl: product.colorPhotos[color] ?? product.imageUrl ?? null, placementPreviewUrlBack: product.colorPhotosBack[color] ?? product.imageUrlBack ?? null, }); setShowAddToCartModal(true); }; return (
{/* Photo */}
{hasBack && (
)}
{renderPhoto(view)}
{/* Controls */}

{product.name}

{product.description}

{product.onSale && product.originalPrice != null && ( )}

Color

{product.colors.map((c) => (
{color && (

Selected: {getColorName(color)}

)}
{product.imageUrl && !product.photoRecolorable && Object.keys(product.colorPhotos).length === 0 && (

This product uses a real photo, so the picture won't change color — your pick is still saved with the order.

)}
{product.sizes.length > 0 && (

Size

{product.sizes.map((s) => ( ))}
)}
{quantity}

💡 Color note: There may be slight color differences based on lighting and screen settings for personalized, plain, and ready-made items. Your actual item may vary slightly from the preview shown.

setShowLoginPrompt(false)} /> setShowAddToCartModal(false)} productName={product.name} />
); }