import Link from 'next/link'; import Image from 'next/image'; import { getCollectionProducts } from 'lib/shopify'; const formatPrice = ({ amount, currencyCode }) => { const USDollar = new Intl.NumberFormat('en-US', { style: 'currency', currency: currencyCode, }); return USDollar.format(amount); }; const formatPriceRange = ({ maxVariantPrice, minVariantPrice }) => { if (maxVariantPrice.amount == minVariantPrice.amount) { return `${formatPrice(maxVariantPrice)}`; } else { return `${formatPrice(minVariantPrice)} - ${formatPrice( maxVariantPrice )}`; } }; const PriceRanges = ({ priceRange, compareAtPriceRange, availableForSale }) => { const onSale = (compareAtPriceRange?.minVariantPrice?.amount ?? 0) > (priceRange?.minVariantPrice?.amount ?? 0) || (compareAtPriceRange?.maxVariantPrice?.amount ?? 0) > (priceRange?.maxVariantPrice?.amount ?? 0); const isForSale = (priceRange?.maxVariantPrice?.amount ?? 0) > 0; return (
{availableForSale ? ( isForSale && ( <> <> {onSale && ( {formatPriceRange(compareAtPriceRange)}{' '} )} > {formatPriceRange(priceRange)} > ) ) : ( Sold Out )}
); }; export async function HomeProduct({ product }) { const featuredImage = product?.images?.[0]; const collections = product?.collections?.nodes; return ({product?.title}
{collections && collections.length > 0 && ({`(${collections ?.map(collection => collection?.title) .join(', ')})`}
)}{`No products found`}
) : (