"use client"; import { Minus, Plus, ShoppingBag, Tag, Truck, X } from "lucide-react"; import { useState } from "react"; import { AspectRatio } from "@/components/ui/aspect-ratio"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Progress } from "@/components/ui/progress"; import { ScrollArea } from "@/components/ui/scroll-area"; import { Separator } from "@/components/ui/separator"; import { Sheet, SheetContent, SheetHeader, SheetTitle, SheetTrigger, } from "@/components/ui/sheet"; import { cn } from "@/lib/utils"; interface CartItem { id: string; name: string; image: string; price: number; quantity: number; variant?: string; } interface UpsellProduct { id: string; name: string; image: string; price: number; } const DEFAULT_ITEMS: CartItem[] = [ { id: "1", name: "هدفون بیسیم نویزکنسل", image: "/block-media/shadcnblocks/block/ecommerce/electronics/Modern-White-Headphones-1.png", price: 249.99, quantity: 1, }, { id: "2", name: "کیف چرمی پریمیوم", image: "/block-media/shadcnblocks/block/ecommerce/accessories/Elegant-Watch-on-Womans-Wrist-1.png", price: 79.0, quantity: 1, }, ]; const DEFAULT_UPSELLS: UpsellProduct[] = [ { id: "u1", name: "پایه هدفون", image: "/block-media/shadcnblocks/block/placeholder-1.svg", price: 29.99, }, { id: "u2", name: "کیف حمل", image: "/block-media/shadcnblocks/block/placeholder-2.svg", price: 39.99, }, ]; const FREE_SHIPPING_THRESHOLD = 150; interface ShoppingCart19Props { items?: CartItem[]; upsells?: UpsellProduct[]; className?: string; } const ShoppingCart19 = ({ items: initialItems = DEFAULT_ITEMS, upsells = DEFAULT_UPSELLS, className, }: ShoppingCart19Props) => { const [items, setItems] = useState(initialItems); const [promoCode, setPromoCode] = useState(""); const [isOpen, setIsOpen] = useState(false); const updateQuantity = (id: string, delta: number) => { setItems((prev) => prev .map((item) => item.id === id ? { ...item, quantity: Math.max(0, item.quantity + delta) } : item, ) .filter((item) => item.quantity > 0), ); }; const removeItem = (id: string) => { setItems((prev) => prev.filter((item) => item.id !== id)); }; const addUpsell = (product: UpsellProduct) => { const existing = items.find((item) => item.id === product.id); if (existing) { updateQuantity(product.id, 1); } else { setItems((prev) => [...prev, { ...product, quantity: 1 }]); } }; const formatPrice = (price: number) => { return new Intl.NumberFormat("fa-IR", { style: "currency", currency: "IRR", }).format(price); }; const subtotal = items.reduce( (sum, item) => sum + item.price * item.quantity, 0, ); const itemCount = items.reduce((sum, item) => sum + item.quantity, 0); const freeShippingProgress = Math.min( (subtotal / FREE_SHIPPING_THRESHOLD) * 100, 100, ); const amountToFreeShipping = FREE_SHIPPING_THRESHOLD - subtotal; return (
{item.variant}
)}شاید اینها را هم بپسندید
{product.name}
{formatPrice(product.price)}
برای شروع، محصولی اضافه کنید