import cn from 'classnames' import Image from 'next/image' import { NextSeo } from 'next-seo' import { FC, useState } from 'react' import s from './ProductView.module.css' import { useUI } from '@components/ui' import { Swatch, ProductSlider } from '@components/product' import { Button, Container, Text } from '@components/ui' import { usePrice } from '@framework/product' import { useAddItem } from '@framework/cart' import { getCurrentVariant, getProductOptions, SelectedOptions, } from '../helpers' import WishlistButton from '@components/wishlist/WishlistButton' interface Props { className?: string children?: any product: Product } const ProductView: FC = ({ product }) => { const addItem = useAddItem() const { price } = usePrice({ amount: product.price.value, baseAmount: product.price.retailValue, currencyCode: product.price.currencyCode!, }) const { openSidebar } = useUI() const options = getProductOptions(product) const [loading, setLoading] = useState(false) const [choices, setChoices] = useState({ size: null, color: null, }) const variant = getCurrentVariant(product, choices) || product.variants[0] const addToCart = async () => { setLoading(true) try { await addItem({ productId: Number(product.id), variantId: Number(product.variants[0].id), }) openSidebar() setLoading(false) } catch (err) { setLoading(false) } } return (

{product.name}

{price} {` `} {product.price?.currencyCode}
{product.images.map((image, i) => (
{image.alt
))}
{options?.map((opt: any) => (

{opt.displayName}

{opt.values.map((v: any, i: number) => { const active = (choices as any)[opt.displayName] return ( { setChoices((choices) => { return { ...choices, [opt.displayName]: v.label, } }) }} /> ) })}
))}
) } export default ProductView