import { Link } from "react-router"; import type { ShopifyProduct } from "@reacteditor/field-shopify"; import { useProduct } from "@/hooks/use-shopify-products"; import { useShopifyCart } from "@/hooks/use-shopify-cart"; import { Typography } from "@/components/Typography"; import { Skeleton } from "@/components/ui/skeleton"; import { cn } from "@/lib/utils"; export type FeaturedProductProps = { product: ShopifyProduct | null; tagline: string; ctaLabel: string; align: "left" | "right"; tone: "default" | "muted"; }; export function FeaturedProductView({ product: selected, tagline, ctaLabel, align, tone, }: FeaturedProductProps) { const { product: full, loading } = useProduct(selected?.handle ?? null); const product: any = full ?? selected; const cart = useShopifyCart(); if (!product) { return ( ); } const image = product.images?.edges?.[0]?.node ?? (selected as any)?.featuredImage ?? null; const variant = product.variants?.edges?.[0]?.node; const price = product.priceRange?.minVariantPrice; const formatted = price ? new Intl.NumberFormat("en-US", { style: "currency", currency: price.currencyCode, }).format(parseFloat(price.amount)) : null; return ( {image ? ( ) : ( )} {tagline ? ( {tagline} ) : null} {product.title} {formatted ? ( {formatted} ) : null} {product.description ? ( {product.description} ) : null} { if (!variant) return; await cart.addItem(variant.id, 1); cart.openCart(); }} className="inline-flex items-center justify-center rounded-md bg-foreground px-6 py-3 text-sm font-medium tracking-wide text-background hover:opacity-90" > {ctaLabel} View details ); }
{tagline}