"use client"; import { CheckCircle2, ShoppingBag, TriangleAlert, Truck } from "lucide-react"; import { useState } from "react"; import { Button } from "@/components/ui/button"; import type { Product } from "@/lib/headless/types"; import { formatMoney, LOW_STOCK_THRESHOLD } from "@/lib/utils"; import { useCartStore } from "@/store/cart-store"; export function ProductPurchase({ product }: { product: Product }) { const [variantId, setVariantId] = useState(product.variants[0]?.id); const addItem = useCartStore((state) => state.addItem); const selectedVariant = product.variants.find((variant) => variant.id === variantId) ?? product.variants[0]; const lowStock = selectedVariant?.inventoryQuantity !== null && selectedVariant?.inventoryQuantity !== undefined && selectedVariant.inventoryQuantity > 0 && selectedVariant.inventoryQuantity <= LOW_STOCK_THRESHOLD ? selectedVariant.inventoryQuantity : null; return
{product.variants.map((variant) => )}
{formatMoney(product.price, product.currency)}{product.compareAtPrice && {formatMoney(product.compareAtPrice, product.currency)}}
{lowStock !== null ? Quedan {lowStock} unidades : Disponibilidad por confirmar}Envíos nacionales
; }