import { Check } from 'lucide-react'; import { cn } from '@/lib/utils'; import { useStorefront } from '../context'; import { ProductImage } from '../product-card'; import { storefrontText } from '../text'; import { formatPrice } from '../theme'; import type { FeaturedProductSection } from '../types'; import { Container, Eyebrow, SfButton } from '../ui'; /** * One product, shown large. * * - Linked to a real product: its real name, price, photo and page are used. The AI's words stay as the description. * - Not linked, store has real products: no price is shown, because the AI's price is only an example. * - Not linked, store has no products yet: the AI's example name and price are shown, so a new store never looks empty. */ export function FeaturedProduct({ section, }: { section: FeaturedProductSection; }) { const { eyebrow, description, bullets, cta, productSlug } = section.content; const { featuredProducts, products, language } = useStorefront(); const t = storefrontText(language); const product = productSlug ? featuredProducts[productSlug] : undefined; const showExamplePrice = !product && products.length === 0; const name = product?.name ?? section.content.name; const href = product ? `/products/${product.slug}` : cta.href; return (
{product && !product.in_stock && ( {t.soldOut} )}
{eyebrow && {eyebrow}}

{name}

{product && (

{product.price_varies ? t.from(formatPrice(product.price)) : formatPrice(product.price)} {!product.price_varies && product.compare_at_price !== null && ( {formatPrice(product.compare_at_price)} )}

)} {showExamplePrice && (

{formatPrice(section.content.price)}

)}

{description}

{bullets.length > 0 && (
    {bullets.map((bullet) => (
  • {bullet}
  • ))}
)} {product && !product.in_stock ? t.viewProduct : cta.label}
); }