import cn from 'classnames' 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, LoadingDots } 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' interface Props { className?: string children?: any product: Product } interface Choices { size?: string | null color?: string | null } const COLORS: Colors[] = ['pink', 'black', 'white'] const SIZES = ['s', 'm', 'l', 'xl', 'xxl'] const ProductView: FC = ({ product, className }) => { 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) { // Error err. setLoading(false) } } const activeSize = choices.size const activeColor = choices.color return (

{product.name}

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

Color

{COLORS.map((color) => ( setChoices((choices) => { return { ...choices, color } }) } /> ))}

Size

{SIZES.map((size) => { return ( setChoices((choices) => ({ ...choices, size })) } /> ) })}
) } export default ProductView