import { NextSeo } from 'next-seo' import { FC, useState } from 'react' import s from './ProductView.module.css' import { Colors } from '@components/ui/types' 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 type { Product } from '@lib/bigcommerce/api/operations/get-product' import { getProductOptions } from '../helpers' interface Props { className?: string children?: any product: Product } interface Choices { size?: string | null color?: string | null } const ProductView: FC = ({ product, className }) => { const options = getProductOptions(product) // console.log(options) const addItem = useAddItem() const { openSidebar } = useUI() const [choices, setChoices] = useState({ size: null, color: null, }) const [loading, setLoading] = useState(false) 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) } } const activeSize = choices.size const activeColor = choices.color 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) => { return ( setChoices((choices) => { return { ...choices, [opt.displayName]: v.label, } }) } /> ) })}
))}
) } export default ProductView