import React, { useState } from 'react'; import { X, Minus, Plus, Trash2, ShoppingBag, CreditCard } from 'lucide-react'; import { Button } from '../ui/Button'; import { Card } from '../ui/Card'; import { Badge } from '../ui/Badge'; import { useCartStore } from '../../stores/cartStore'; import { CheckoutWizard } from './CheckoutWizard'; export interface CartDrawerProps { onCheckout?: () => void; } export const CartDrawer: React.FC = ({ onCheckout }) => { const { isOpen, setIsOpen, updateQuantity, removeItem, clearCart, getTotals, getItemsByEvent, hasItems } = useCartStore(); const [showCheckoutWizard, setShowCheckoutWizard] = useState(false); const totals = getTotals(); const itemsByEvent = getItemsByEvent(); const handleClose = () => { setIsOpen(false); }; const handleQuantityChange = (itemId: string, newQuantity: number) => { updateQuantity(itemId, newQuantity); }; const handleRemoveItem = (itemId: string) => { removeItem(itemId); }; const handleClearCart = () => { if (window.confirm('Are you sure you want to clear your cart?')) { clearCart(); } }; const handleCheckout = () => { setShowCheckoutWizard(true); onCheckout?.(); }; if (!isOpen) return null; return ( <> {/* Backdrop */}
{/* Drawer */}
{/* Header */}

Shopping Cart

{totals.totalQuantity > 0 && ( {totals.totalQuantity} item{totals.totalQuantity !== 1 ? 's' : ''} )}

Review and manage items in your shopping cart before checkout

{/* Content */}
{!hasItems() ? (

Your cart is empty

Add some tickets to get started!

) : (
{/* Cart Items by Event */} {Object.entries(itemsByEvent).map(([eventId, eventItems]) => (

{eventItems[0]?.eventTitle}

{eventItems.map((item) => (
{/* Item Details */}

{item.ticketTypeName}

{item.ticketTypeDescription && (

{item.ticketTypeDescription}

)}

${(item.priceInCents / 100).toFixed(2)} each

{/* Quantity Controls */}
{item.quantity}

${((item.priceInCents * item.quantity) / 100).toFixed(2)}

{item.inventory !== undefined && (

{item.inventory - item.quantity} left

)}
{/* Seat Numbers (if applicable) */} {item.seatNumbers && item.seatNumbers.length > 0 && (
Seats: {item.seatNumbers.join(', ')}
)}
))}
))} {/* Clear Cart Button */}
)}
{/* Footer with Totals and Checkout */} {hasItems() && (
{/* Totals */}
Subtotal ({totals.totalQuantity} items) ${totals.subtotal.toFixed(2)}
Platform fee ${totals.platformFee.toFixed(2)}
Total ${totals.total.toFixed(2)}
{/* Checkout Button */}

Secure checkout powered by Stripe

)}
{/* Checkout Wizard */} setShowCheckoutWizard(false)} /> ); };