import { Button, ComposedModal, InlineNotification, ModalBody, ModalFooter, ModalHeader, ProgressBar } from "@carbon/react"; import type { ExportProgress } from "../lib/exportFlow"; export interface FlattenProgressModalProps { open: boolean; progress: ExportProgress | null; /** The flatten failed: show it with Retry and "Export searchable instead". */ error: string | null; onCancel: () => void; onRetry: () => void; onExportSearchable: () => void; onClose: () => void; } function describe(p: ExportProgress | null): { label: string; value?: number; max: number } { if (p?.phase === "flattening" && p.page && p.pages) { // The page being rendered counts as in progress, so the bar shows the pages finished before it. return { label: `Rendering page ${p.page} of ${p.pages}…`, value: p.page - 1, max: p.pages }; } if (p?.phase === "assembling") return { label: "Building the PDF…", value: 1, max: 1 }; return { label: "Preparing the invoice…", max: 1 }; } export default function FlattenProgressModal({ open, progress, error, onCancel, onRetry, onExportSearchable, onClose }: FlattenProgressModalProps) { const { label, value, max } = describe(progress); return ( (error ? onClose() : onCancel())} aria-label="Flattened PDF export"> {error ? ( ) : ( )} {error ? ( // Three direct children: Carbon lays a three-button footer out differently from a two-button one. ) : ( )} ); }