import { useParams, Link } from 'react-router-dom' import { usePurchase } from '../hooks/useApi.ts' import { StoreIcon } from '../components/StoreIcon.tsx' export function PurchaseDetail() { const { id } = useParams<{ id: string }>() const { data: purchase, isLoading, error } = usePurchase(id ?? '') if (isLoading) { return (
{[1, 2, 3, 4].map((i) => (
))}
) } if (error || !purchase) { return (

Purchase not found.

Back to purchases
) } return (
{/* Back link */} Purchases {/* Receipt header */}

{purchase.storeName}

{new Date(purchase.date).toLocaleDateString('en-US', { weekday: 'long', month: 'long', day: 'numeric', year: 'numeric', })}

{/* Line items */}
{purchase.items.map((item) => (

{item.name}

{item.quantity > 1 && (

{item.quantity} × ${item.unitPrice.toFixed(2)}

)}
${item.price.toFixed(2)} ))}
{/* Total */}
Total ${purchase.total.toFixed(2)}
) }