import React from 'react'; import { ShoppingCart, ShoppingBag, Trash2, RefreshCw, CreditCard, XCircle } from 'lucide-react'; import type { ModuleItem, Currency, UserProfile, VerificationResult } from '../../types'; interface CartDrawerProps { cart: ModuleItem[]; currency: Currency; setCurrency: (c: Currency) => void; toggleCartItem: (module: ModuleItem) => void; couponCode: string; setCouponCode: (code: string) => void; appliedCoupon: string | null; applyPromoCode: () => void; removePromoCode: () => void; pricingCalc: any; loadingPricing: boolean; loggedInUser: UserProfile | null; onUpdateBillingPhone: () => void; verificationResult: VerificationResult | null; checkoutLoading: boolean; handleCheckout: () => void; } export const CartDrawer: React.FC = ({ cart, currency, setCurrency, toggleCartItem, couponCode, setCouponCode, appliedCoupon, applyPromoCode, removePromoCode, pricingCalc, loadingPricing, loggedInUser, onUpdateBillingPhone, verificationResult, checkoutLoading, handleCheckout, }) => { return (

Cart Summary

{cart.length} {cart.length === 1 ? 'Item' : 'Items'}
{/* Currency selector toggle */}
Billing Currency:
{/* Selected modules list */} {cart.length === 0 ? (

Your checkout cart is empty. Select from curriculum.

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

{item.name}

{item.category}

{(() => { const calculatedItem = pricingCalc?.currency === currency ? pricingCalc?.cart_items?.find((ci: any) => ci.code === item.code) : null; const price = calculatedItem ? calculatedItem.price : (currency === 'INR' ? item.priceInr : currency === 'EUR' ? item.priceEur : item.priceUsd); const symbol = currency === 'INR' ? '₹' : currency === 'EUR' ? '€' : '$'; return `${symbol}${price}`; })()}
))}
)} {/* Coupon Code Input */} {cart.length > 0 && (
setCouponCode(e.target.value)} placeholder="e.g. AGENT40, EVENT_NEW" className="flex-1 bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs font-semibold text-slate-800 focus:outline-none focus:border-indigo-500 placeholder:text-slate-400 uppercase" />
{appliedCoupon && (pricingCalc?.coupon_error || !pricingCalc?.coupon_applied || pricingCalc?.coupon_applied === 'None' ? (
⚠️ {pricingCalc?.coupon_error || 'Invalid or expired coupon code.'}
) : (
Coupon Active: {appliedCoupon} ✓{' '} {pricingCalc?.coupon_applied && pricingCalc.coupon_applied !== 'None' ? `(${pricingCalc.coupon_applied.replace(/Code: \w+ - /, '')})` : ''}
))}
)} {/* Checkout Summary Calculations */} {loadingPricing && (!pricingCalc || pricingCalc.currency !== currency) && (
Calculating {currency} pricing...
)} {pricingCalc && pricingCalc.currency === currency && cart.length > 0 && (
Base Subtotal {currency === 'INR' ? `₹${pricingCalc.base_subtotal}` : currency === 'EUR' ? `€${pricingCalc.base_subtotal}` : `$${pricingCalc.base_subtotal}`}
{pricingCalc.renewal_discount_amount > 0 && (
Early Renewal Discount (20%) -{currency === 'INR' ? `₹${pricingCalc.renewal_discount_amount}` : currency === 'EUR' ? `€${pricingCalc.renewal_discount_amount}` : `$${pricingCalc.renewal_discount_amount}`}
)} {pricingCalc.bundle_discount_amount > 0 && (
Bundle Discount -{currency === 'INR' ? `₹${pricingCalc.bundle_discount_amount}` : currency === 'EUR' ? `€${pricingCalc.bundle_discount_amount}` : `$${pricingCalc.bundle_discount_amount}`}
)} {pricingCalc.coupon_discount_amount > 0 && (
Coupon Discount ({appliedCoupon}) -{currency === 'INR' ? `₹${pricingCalc.coupon_discount_amount}` : currency === 'EUR' ? `€${pricingCalc.coupon_discount_amount}` : `$${pricingCalc.coupon_discount_amount}`}
)} {pricingCalc.total_discounts > 0 && !pricingCalc.renewal_discount_amount && !pricingCalc.bundle_discount_amount && !pricingCalc.coupon_discount_amount && (
Total Discounts -{currency === 'INR' ? `₹${pricingCalc.total_discounts}` : currency === 'EUR' ? `€${pricingCalc.total_discounts}` : `$${pricingCalc.total_discounts}`}
)} {pricingCalc.convenience_fee > 0 && (
Gateway fee ({pricingCalc.convenience_fee_rate}%) {currency === 'INR' ? `₹${pricingCalc.convenience_fee}` : currency === 'EUR' ? `€${pricingCalc.convenience_fee}` : `$${pricingCalc.convenience_fee}`}
)} {pricingCalc.gst_amount > 0 && (
GST (18%) {currency === 'INR' ? `₹${pricingCalc.gst_amount}` : currency === 'EUR' ? `€${pricingCalc.gst_amount}` : `$${pricingCalc.gst_amount}`}
(Taxable Amount:{' '} {currency === 'INR' ? `₹${pricingCalc.taxable_amount}` : currency === 'EUR' ? `€${pricingCalc.taxable_amount}` : `$${pricingCalc.taxable_amount}`} )
)}
Total Chargeable {currency === 'INR' ? `₹${pricingCalc.grand_total}` : currency === 'EUR' ? `€${pricingCalc.grand_total}` : `$${pricingCalc.grand_total}`}
)} {/* Billing Details Prefill Summary */} {loggedInUser && cart.length > 0 && (
Billing Profile
Email: {loggedInUser.email}
Phone: {loggedInUser.phone_number || ( Required for checkout )}
)} {/* Verification failure result badge */} {verificationResult && verificationResult.status === 'error' && (

Verification Failed

{verificationResult.message}

)} {/* Checkout Trigger */} {cart.length > 0 && (

* Integrated with Razorpay Gateway API (Test Mode).

)}
); };