"use client" import { Button } from "@/components/ui/button" import { Sheet, SheetContent, SheetFooter, SheetHeader, SheetTitle, SheetTrigger } from "@/components/ui/sheet" import { useCart } from "@/context/cart-context" import { Minus, Plus, ShoppingCartIcon as CartIcon, Trash2 } from "lucide-react" import { useRouter } from "next/navigation" import { Separator } from "./ui/separator" import { motion, AnimatePresence } from "framer-motion" import { notify } from "@/lib/event-bus" export function ShoppingCart() { const { cart, updateQuantity, removeFromCart, clearCart } = useCart() const router = useRouter() const totalItems = cart.reduce((total, item) => total + item.quantity, 0) const totalPrice = cart.reduce((total, item) => total + item.price * item.quantity, 0) const handleCheckout = () => { router.push("/cart") } const handleRemoveItem = (id: number, title: string) => { removeFromCart(id) notify({ title: "已移除商品", message: title, type: "info", duration: 2000, }) } return ( 购物车
{cart.length === 0 ? (

您的购物车是空的

) : ( {cart.map((item) => (
{item.title}

{item.title}

¥{item.price.toFixed(2)}

{item.quantity}

¥{(item.price * item.quantity).toFixed(2)}

))}
)}
{cart.length > 0 && ( <>
小计 ¥{totalPrice.toFixed(2)}
运费 免费
总计 ¥{totalPrice.toFixed(2)}
)}
) }