import { FC, useState } from 'react' import cn from 'classnames' import Image from 'next/image' import { NextSeo } from 'next-seo' import s from './ProductView.module.css' import { Heart } from '@components/icons' import { useUI } from '@components/ui/context' import { Swatch, ProductSlider } from '@components/product' import { Button, Container } from '@components/ui' import { HTMLContent } from '@components/core' import useAddItem from '@lib/bigcommerce/cart/use-add-item' import type { ProductNode } from '@lib/bigcommerce/api/operations/get-product' import { getProductOptions } from '../helpers' import WishlistButton from '@components/wishlist/WishlistButton' interface Props { className?: string children?: any product: ProductNode } const ProductView: FC = ({ product, className }) => { const addItem = useAddItem() const { openSidebar } = useUI() const options = getProductOptions(product) const [loading, setLoading] = useState(false) const [choices, setChoices] = useState>({ size: null, color: null, }) const addToCart = async () => { setLoading(true) try { await addItem({ productId: product.entityId, variantId: product.variants.edges?.[0]?.node.entityId!, }) openSidebar() setLoading(false) } catch (err) { setLoading(false) } } return (

{product.name}

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

{opt.displayName}

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