import cn from 'classnames' import { FC, useState } from 'react' import s from './ProductView.module.css' import { Button, Container } from '@components/ui' import { Swatch } from '@components/product' import { Colors } from '@components/ui/types' import type { Product } from '@lib/bigcommerce/api/operations/get-product' import useAddItem from '@lib/bigcommerce/cart/use-add-item' import { useUI } from '@components/ui/context' 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 addToCart = async () => { // TODO: loading state by awating the promise await addItem({ productId: product.entityId, variantId: product.variants.edges?.[0]?.node.entityId!, }) openSidebar() } const activeSize = choices.size const activeColor = choices.color return (

{product.name}

{product.prices?.price.value} {` `} {product.prices?.price.currencyCode}

Color

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

Size

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