import type { Product, ProductVariant } from 'lib/storm/types/product' import { cn } from 'lib/utils' import { Heart } from 'lucide-react' import { useTranslations } from 'next-intl' import React, { FC, useState } from 'react' type Props = { productId: Product['id'] variant: ProductVariant } & React.ButtonHTMLAttributes const WishlistButton: FC = ({ productId, variant, className, ...props }) => { const [loading, setLoading] = useState(false) const t = useTranslations('ui.button') // @ts-ignore Wishlist is not always enabled // const itemInWishlist = data?.items?.find( // // @ts-ignore Wishlist is not always enabled // (item) => item.product_id === productId && item.variant_id === variant.id // ) const handleWishlistChange = async (e: any) => { e.preventDefault() if (loading) return // A login is required before adding an item to the wishlist // if (!customer) { // setModalView('LOGIN_VIEW') // return openModal() // } // setLoading(true) // try { // if (itemInWishlist) { // await removeItem({ id: itemInWishlist.id! }) // } else { // await addItem({ // productId, // variantId: variant?.id!, // }) // } // setLoading(false) // } catch (err) { // setLoading(false) // } } return ( ) } export default WishlistButton