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 { useUI } from '@components/ui/context' import { Swatch, ProductSlider } from '@components/product' import { Button, Container, Text } from '@components/ui' import usePrice from '@bigcommerce/storefront-data-hooks/use-price' import useAddItem from '@bigcommerce/storefront-data-hooks/cart/use-add-item' import type { ProductNode } from '@bigcommerce/storefront-data-hooks/api/operations/get-product' import { getCurrentVariant, getProductOptions, SelectedOptions, } from '../helpers' import WishlistButton from '@components/wishlist/WishlistButton' interface Props { className?: string children?: any product: ProductNode } const ProductView: FC = ({ product }) => { const addItem = useAddItem() const { price } = usePrice({ amount: product.prices?.price?.value, baseAmount: product.prices?.retailPrice?.value, currencyCode: product.prices?.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.edges?.[0] 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}

{price} {` `} {product.prices?.price.currencyCode}
{product.images.edges?.map((image, i) => (
{image?.node.altText
))}
{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