"use client"; import { useEffect } from "react"; import { motion, AnimatePresence } from "framer-motion"; import Image from "next/image"; import Link from "next/link"; import { X, Minus, Plus, Trash2, ShoppingBag } from "lucide-react"; import { useSaleorCheckoutStore } from "@/stores/saleorCheckoutStore"; import { formatPrice } from "@/lib/saleor"; export default function CartDrawer() { const { checkout, isOpen, isLoading, error, closeCart, removeLine, updateLine, getTotal, getLineCount, getLines, initCheckout, clearError, } = useSaleorCheckoutStore(); const lines = getLines(); const total = getTotal(); const lineCount = getLineCount(); // Initialize checkout on mount useEffect(() => { initCheckout(); }, [initCheckout]); // Lock body scroll when cart is open useEffect(() => { if (isOpen) { document.body.style.overflow = "hidden"; } else { document.body.style.overflow = ""; } return () => { document.body.style.overflow = ""; }; }, [isOpen]); return ( {isOpen && ( <> {/* Backdrop */} {/* Drawer */} {/* Header */}

Your Cart ({lineCount})

{/* Error Message */} {error && (

{error}

)}
{/* Cart Items */}
{lines.length === 0 ? (

Your cart is empty

Looks like you haven't added anything to your cart yet.

Start Shopping
) : (
{lines.map((line) => (
{/* Product Image */}
{line.variant.product.media[0]?.url ? ( {line.variant.product.name} ) : (
)}
{/* Product Info */}

{line.variant.product.name}

{line.variant.name !== "Default" && (

{line.variant.name}

)}

{formatPrice( line.variant.pricing?.price?.gross?.amount || 0, line.variant.pricing?.price?.gross?.currency )}

{/* Quantity Controls */}
{line.quantity}
{/* Remove Button */}
))}
)}
{/* Footer with Checkout */} {lines.length > 0 && (
{/* Order Summary */}
{/* Subtotal */}
Subtotal {formatPrice(checkout?.subtotalPrice?.gross?.amount || 0)}
{/* Shipping */}
Shipping {checkout?.shippingPrice?.gross?.amount ? formatPrice(checkout.shippingPrice.gross.amount) : "Calculated at checkout" }
{/* Divider */}
{/* Total */}
Total {formatPrice(total)}
{(checkout?.subtotalPrice?.gross?.amount || 0) < 5000 && (

Free shipping on orders over {formatPrice(5000)}

)}
{/* Actions */}
{/* Checkout Button */} {isLoading ? "Processing..." : "Checkout"} {/* Continue Shopping */}
)} )} ); }