import cn from 'classnames' import { NextSeo } from 'next-seo' import s from './ProductView.module.css' import { FC, useState, useEffect } from 'react' import { useUI } from '@components/ui/context' import { Button, Container } from '@components/ui' import { Swatch, ProductSlider } from '@components/product' import useAddItem from '@lib/bigcommerce/cart/use-add-item' import { isDesktop } from '@lib/browser' import type { ProductNode } from '@lib/bigcommerce/api/operations/get-product' import { getProductOptions } from '../helpers' import { Heart } from '@components/icon' 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 [validMedia, setValidMedia] = useState(false) const [choices, setChoices] = useState>({ size: null, color: null, }) useEffect(() => { setValidMedia(isDesktop()) }, []) 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}
{/** TODO: Change with Image Component **/} {product.images.edges?.map((image, i) => ( ))}
{options?.map((opt: any) => (

{opt.displayName}

{opt.values.map((v: any) => { const active = choices[opt.displayName] return ( { setChoices((choices) => { console.log(choices) return { ...choices, [opt.displayName]: v.label, } }) }} /> ) })}
))}
{/* TODO make it work */}
) } export default ProductView