// src/app/panier/page.tsx 'use client'; import { useCartActions } from '@/hooks/useCartSync';import { formatPrice } from '@/lib/woocommerce'; import { Button } from '@/components/ui/button'; import { Card, CardContent } from '@/components/ui/card'; import { Separator } from '@/components/ui/separator'; import { Badge } from '@/components/ui/badge'; import { Input } from '@/components/ui/input'; import { ShoppingBag, Trash2, Plus, Minus, ArrowRight, Truck, Shield, Tag } from 'lucide-react'; import Image from 'next/image'; import Link from 'next/link'; import { useState } from 'react'; import { cn } from '@/lib/utils'; export default function CartPage(): JSX.Element { const { cart, updateQuantity, removeFromCart, clearCart } = useCart(); const [promoCode, setPromoCode] = useState(''); const [isPromoApplied, setIsPromoApplied] = useState(false); const [promoDiscount, setPromoDiscount] = useState(0); const subtotal = cart.total; const shipping = subtotal >= 50000 ? 0 : 5000; // Livraison gratuite à partir de 50.000 MRU const discount = isPromoApplied ? promoDiscount : 0; const total = subtotal + shipping - discount; const handleQuantityChange = (productId: number, newQuantity: number): void => { if (newQuantity <= 0) { removeFromCart(productId); } else { updateQuantity(productId, newQuantity); } }; const applyPromoCode = (): void => { // Codes promo factices pour la démo const promoCodes: { [key: string]: number } = { 'WELCOME10': 0.1, 'SUMMER20': 0.2, 'FIRST5': 0.05, }; const discountPercent = promoCodes[promoCode.toUpperCase()]; if (discountPercent) { setIsPromoApplied(true); setPromoDiscount(subtotal * discountPercent); } }; const removePromoCode = (): void => { setIsPromoApplied(false); setPromoDiscount(0); setPromoCode(''); }; if (cart.items.length === 0) { return (
Découvrez notre collection de melhfa exceptionnelles et commencez votre shopping.
Vérifiez vos articles avant de procéder au paiement
Prix unitaire: {formatPrice(item.price)}
{formatPrice(item.total)}
Codes de démonstration disponibles:
• WELCOME10 (10% de réduction)
• SUMMER20 (20% de réduction)