import React from 'react'; import Link from 'next/link'; import Image from 'next/image'; import { truncate } from '@/lib/utils'; interface ProductImage { url: string; altText?: string | null; } interface ProductPrice { amount: string; currencyCode: string; } interface ProductVariant { id: string; title: string; price: ProductPrice; availableForSale: boolean; } interface Product { id: string; title: string; description?: string; handle: string; images: { edges: Array<{ node: ProductImage; }>; }; priceRange: { minVariantPrice: ProductPrice; }; compareAtPriceRange?: { minVariantPrice: ProductPrice; }; variants: { edges: Array<{ node: ProductVariant; }>; }; } interface ProductCardProps { product: Product; } const ProductCard: React.FC = ({ product }) => { const firstImage = product.images.edges[0]?.node; const price = product.priceRange.minVariantPrice; const compareAtPrice = product.compareAtPriceRange?.minVariantPrice; const hasDiscount = compareAtPrice && parseFloat(compareAtPrice.amount) > parseFloat(price.amount); const firstVariant = product.variants.edges[0]?.node; const isAvailable = firstVariant?.availableForSale || false; const formatPrice = (amount: string) => { return `$${parseFloat(amount).toFixed(2)}`; }; return ( {/* Product Image */}
{firstImage ? ( {firstImage.altText ) : (
)} {hasDiscount && compareAtPrice && ( SALE )} {!isAvailable && ( SOLD OUT )}
{/* Product Info */}

{truncate(product.title, 65)}

{formatPrice(price.amount)} {hasDiscount && compareAtPrice && ( {formatPrice(compareAtPrice.amount)} )}
); }; export default ProductCard;