'use client'; import React from 'react'; import { useShopifyCart, redirectToCheckout } from '@/hooks/use-shopify-cart'; import { Button } from '@/components/ui/button'; import { Spinner } from '@/components/ui/spinner'; import { Sheet, SheetContent, SheetHeader, SheetTitle, SheetBody, AnimatePresence, } from '@/components/ui/sheet'; const CartDrawer: React.FC = () => { const { isOpen, closeCart, items, itemCount, totalAmount, checkoutUrl, loading, removeItem, updateItemQuantity } = useShopifyCart(); const handleCheckout = () => { if (checkoutUrl) { redirectToCheckout(checkoutUrl); } }; const getItemImage = (item: typeof items[0]) => { return item.merchandise.image?.url; }; const getSelectedOptions = (item: typeof items[0]) => { return item.merchandise.selectedOptions ?? []; }; return ( !open && closeCart()} side="right"> {isOpen && ( {/* Header */}
Shopping Cart ({itemCount})
{/* Cart Items */} {loading && items.length === 0 ? (
) : items.length === 0 ? (

Your cart is empty

Add some products to get started!

) : (
{items.map((item) => { const image = getItemImage(item); const selectedOptions = getSelectedOptions(item); return (
{/* Product Image */}
{image ? ( {item.merchandise.product.title} ) : (
)}
{/* Product Details */}

{item.merchandise.product.title}

{/* Variant Info */} {selectedOptions.length > 0 && (
{selectedOptions.map((option, index) => ( {option.value} {index < selectedOptions.length - 1 ? ' / ' : ''} ))}
)} {/* Quantity Controls */}
{item.quantity}
{/* Price */}
${parseFloat(item.merchandise.price.amount).toFixed(2)}
{/* Remove Button */}
); })}
)}
{/* Footer - Checkout Section */} {items.length > 0 && (
{/* Subtotal */}
Subtotal ${totalAmount.toFixed(2)}
Shipping and taxes calculated at checkout
{/* Action Buttons */}
)}
)}
); }; export default CartDrawer;