"use client" import * as React from 'react' import { Check } from 'lucide-react' import { Button } from '@open-mercato/ui/primitives/button' import { Alert, AlertDescription } from '@open-mercato/ui/primitives/alert' import { useT } from '@open-mercato/shared/lib/i18n/context' import type { RunnerActiveFormResponse, RunnerSubmission } from '../types' export type CompletionScreenProps = { submission: RunnerSubmission schemaResponse: RunnerActiveFormResponse pdfDownloadEnabled?: boolean onDownloadPdf?: () => void onReturnHome?: () => void /** Per-distribution custom heading; falls back to the default "Thank you!". */ completionTitle?: string | null /** Per-distribution custom body; falls back to the default subtitle. */ completionMessage?: string | null /** Surfaced when a PDF download attempt fails. */ pdfError?: string | null } function formatTime(iso: string | null): string { if (!iso) return '' const parsed = new Date(iso) if (Number.isNaN(parsed.getTime())) return '' return parsed.toLocaleString(undefined, { dateStyle: 'medium', timeStyle: 'short' }) } export function CompletionScreen({ submission, schemaResponse, pdfDownloadEnabled = false, onDownloadPdf, onReturnHome, completionTitle, completionMessage, pdfError, }: CompletionScreenProps) { const t = useT() const submittedAt = submission.submittedAt ?? submission.updatedAt ?? null const submittedLabel = formatTime(submittedAt) const title = completionTitle?.trim() ? completionTitle : t('forms.runner.completion.title', { fallback: 'Thank you!' }) const message = completionMessage?.trim() ? completionMessage : t('forms.runner.completion.subtitle', { fallback: 'Your submission has been recorded.' }) return (

{title}

{message}

{submittedLabel ? (

{t('forms.runner.completion.submitted_at', { fallback: 'Submitted {time}', time: submittedLabel, })}

) : null} {(pdfDownloadEnabled || onReturnHome) ? (
{pdfDownloadEnabled ? ( ) : null} {onReturnHome ? ( ) : null}
) : null} {pdfError ? ( {pdfError} ) : null}
) }