import { jsx as _jsx } from "react/jsx-runtime";
// (C) 2026 GoodData Corporation
import { memo, useState } from "react";
import { defineMessages, useIntl } from "react-intl";
import { getCsvDelimiterState, getCsvDelimiterValidationError, getCsvDelimiterValue, } from "@gooddata/sdk-model";
import { ValidationContextStore, createInvalidNode, useValidationContextValue } from "@gooddata/sdk-ui";
import { ConfirmDialogBase, CsvDelimiterPicker, Overlay } from "@gooddata/sdk-ui-kit";
const alignPoints = [{ align: "cc cc" }];
const messages = defineMessages({
    headline: { id: "dialogs.export.csv.headline", defaultMessage: "Export settings (.csv)" },
    cancel: { id: "cancel" },
    submit: { id: "dialogs.export.submit" },
    delimiterLabel: { id: "dialogs.export.csv.delimiter", defaultMessage: "CSV delimiter" },
});
export const ExportCsvDialog = memo(function ExportCsvDialog({ initialDelimiter, onCancel, onSubmit, }) {
    const intl = useIntl();
    const [value, setValue] = useState(() => getCsvDelimiterState(initialDelimiter));
    const validationContextValue = useValidationContextValue(createInvalidNode());
    const validationError = value.selectedPreset === "custom" ? getCsvDelimiterValidationError(value.customDelimiter) : undefined;
    const isSubmitDisabled = value.selectedPreset === "custom" ? !value.customDelimiter || Boolean(validationError) : false;
    const selectedDelimiter = getCsvDelimiterValue(value.selectedPreset, value.customDelimiter);
    const handleSubmit = () => {
        onSubmit({ delimiter: selectedDelimiter });
    };
    return (_jsx(Overlay, { alignPoints: alignPoints, isModal: true, positionType: "fixed", children: _jsx(ValidationContextStore, { value: validationContextValue, children: _jsx(ConfirmDialogBase, { className: "gd-csv-export-dialog s-gd-csv-export-dialog", displayCloseButton: true, isPositive: true, isSubmitDisabled: isSubmitDisabled, headline: intl.formatMessage(messages.headline), cancelButtonText: intl.formatMessage(messages.cancel), submitButtonText: intl.formatMessage(messages.submit), onCancel: onCancel, onSubmit: handleSubmit, autofocusOnOpen: true, children: _jsx("div", { className: "gd-csv-export-dialog-item", children: _jsx(CsvDelimiterPicker, { value: value, onChange: setValue, validationError: validationError, label: intl.formatMessage(messages.delimiterLabel), onEnterKeyPress: isSubmitDisabled ? undefined : handleSubmit }) }) }) }) }));
});
