"use client"; import { useEffect } from "react"; import type { PaidReceipt } from "../../lib/receipt"; import { downloadReceiptHtml } from "../../lib/receipt"; function money(n: number) { return `₹${n.toLocaleString("en-IN", { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`; } type Props = { open: boolean; loading: boolean; error: string | null; receipt: PaidReceipt | null; onClose: () => void; }; export function OrderReceiptModal({ open, loading, error, receipt, onClose }: Props) { useEffect(() => { if (!open) return; function onKey(e: KeyboardEvent) { if (e.key === "Escape") onClose(); } window.addEventListener("keydown", onKey); return () => window.removeEventListener("keydown", onKey); }, [open, onClose]); if (!open) return null; return (
e.stopPropagation()} >

Order receipt

{receipt?.receiptNumber ?? "Receipt"}

{receipt ? (

{receipt.storeCode} · {new Date(receipt.createdAt).toLocaleString()}

) : null}
{loading ?

Loading receipt…

: null} {!loading && error ?

{error}

: null} {!loading && receipt ? ( <>

Order {receipt.orderId.slice(0, 8)}… · {receipt.paymentMode} {receipt.tokenNumber != null ? ` · Counter #${receipt.tokenNumber}` : ""}

    {receipt.lines.map((line) => (
  • {line.name} × {line.qty} {money(line.lineTotal)}
  • ))}
Subtotal {money(receipt.subtotal)}
Tax {money(receipt.taxTotal)}
Total paid {money(receipt.grandTotal)}
{receipt.receiptEmail ? (

Customer email: {receipt.receiptEmail}

) : null} ) : null}
{receipt ? ( ) : null}
); }