import React from 'react' import Link from 'next/link' import useCart, {useSetCart} from '~/hooks/useCart' import styles from './style.module.css' import axios from 'axios' export default function Card({item}) { const cart = useCart() const setCart = useSetCart() const numInCart = cart?.items?.find(i => i.item.uuid === item.uuid)?.count || 0 let featuredImage = item.images.find(i=>i.featured) || item.images[0] const addToCart = async ev => { if(ev) ev.preventDefault() const {data: newCart} = await axios.post(`/api/cart/add/${item.uuid}`, {count: 1}) setCart(newCart) } const canPurchase = item.number_in_stock > 0 || item.preorder_availability_date !== undefined const availabilityText = item.number_in_stock > 0 ? `${item.number_in_stock} in stock` : item.preorder_availability_date && (-1 * item.number_in_stock < item.preorder_maximum) ? 'Available for pre-order' : 'Currently out of stock' return (
) }