import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { ConnectConfirmationModal } from "@powerhousedao/design-system/connect";
import { closePHModal, exportFile, useDocumentById, usePHModal, validateDocument, } from "@powerhousedao/reactor-browser";
import { useTranslation } from "react-i18next";
export function ExportDocumentWithErrorsModal() {
    const phModal = usePHModal();
    const open = phModal?.type === "exportDocumentWithErrors";
    const documentId = open ? phModal.documentId : undefined;
    const [document] = useDocumentById(documentId);
    const { t } = useTranslation();
    if (!document) {
        return null;
    }
    const validationErrors = validateDocument(document);
    return (_jsx(ConnectConfirmationModal, { header: t("modals.exportDocumentWithErrors.title"), title: t("modals.exportDocumentWithErrors.title"), body: _jsxs("div", { children: [_jsx("p", { children: t("modals.exportDocumentWithErrors.body") }), _jsx("ul", { className: "mt-4 flex list-disc flex-col items-start px-4 text-xs", children: validationErrors.map((error, index) => (_jsx("li", { children: error.message }, index))) })] }), cancelLabel: t("common.cancel"), continueLabel: t("common.export"), onCancel: () => closePHModal(), onContinue: async () => {
            try {
                await exportFile(document);
            }
            catch (error) {
                console.error(error);
            }
            finally {
                closePHModal();
            }
        }, open: open, onOpenChange: (status) => {
            if (!status)
                return closePHModal();
        } }));
}
//# sourceMappingURL=ExportDocumentWithErrorsModal.js.map