import { FC, useState } from 'react' import cn from 'classnames' import Link from 'next/link' import Image from 'next/image' import type { WishlistItem } from '@bigcommerce/storefront-data-hooks/api/wishlist' import usePrice from '@bigcommerce/storefront-data-hooks/use-price' import useRemoveItem from '@bigcommerce/storefront-data-hooks/wishlist/use-remove-item' import useAddItem from '@bigcommerce/storefront-data-hooks/cart/use-add-item' import { useUI } from '@components/ui/context' import { Button, Text } from '@components/ui' import { Trash } from '@components/icons' import s from './WishlistCard.module.css' interface Props { item: WishlistItem } const WishlistCard: FC = ({ item }) => { const product = item.product! const { price } = usePrice({ amount: product.prices?.price?.value, baseAmount: product.prices?.retailPrice?.value, currencyCode: product.prices?.price?.currencyCode!, }) const removeItem = useRemoveItem({ includeProducts: true }) const [loading, setLoading] = useState(false) const [removing, setRemoving] = useState(false) const addItem = useAddItem() const { openSidebar } = useUI() const handleRemove = async () => { setRemoving(true) try { // If this action succeeds then there's no need to do `setRemoving(true)` // because the component will be removed from the view await removeItem({ id: item.id! }) } catch (error) { setRemoving(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) } } return (
{product.images.edges?.[0]?.node.altText

{product.name}

{price}
) } export default WishlistCard