import React, { useState } from 'react'; import { motion } from 'framer-motion'; import { Link, useNavigate } from 'react-router-dom'; import { useStore } from '../src/context/StoreContext'; const Checkout: React.FC = () => { const { cart } = useStore(); const navigate = useNavigate(); const [formData, setFormData] = useState({ email: '', firstName: '', lastName: '', address: '', city: '', postalCode: '' }); const subtotal = cart.reduce((total, item) => total + (item.price * item.quantity), 0); const shipping = subtotal > 150 ? 0 : 15; const total = subtotal + shipping; const handleInputChange = (e: React.ChangeEvent) => { setFormData({ ...formData, [e.target.name]: e.target.value }); }; const handleProceed = (e: React.FormEvent) => { e.preventDefault(); const orderData = { customer_email: formData.email, customer_name: `${formData.firstName} ${formData.lastName}`, shipping_address: { address: formData.address, city: formData.city, postalCode: formData.postalCode }, items: cart.map(item => ({ id: item.id, title: item.title, quantity: item.quantity, price: item.price })), total_amount: total }; navigate('/mock-payment', { state: { orderData } }); }; if (cart.length === 0) { return (

Your bag is empty

View Collections
); } return (
Checkout
{/* Order Summary Form */}

Contact Information

Shipping Address

{/* Cart Preview Sidebar */}

In your bag

{cart.map((item) => (
{item.title}

{item.title}

Qty: {item.quantity}

${(item.price * item.quantity).toFixed(2)}

))}
Subtotal ${subtotal.toFixed(2)}
Shipping {shipping === 0 ? 'Free' : `$${shipping.toFixed(2)}`}
Total ${total.toFixed(2)}
); }; export default Checkout;