import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
// (C) 2022-2026 GoodData Corporation
import { useEffect, useState } from "react";
import noop from "lodash-es/noop.js";
import { FormattedMessage, defineMessage, useIntl } from "react-intl";
import { getPartialDataWarningMessage } from "@gooddata/sdk-ui";
import { DialogBase, UiLink, WidgetNotice } from "@gooddata/sdk-ui-kit";
export function InsightWidgetWarningPartialResult({ className, limitBreaks, isLoading, isExporting, isExportRawVisible, executionResult, isEditMode = false, onExportRawCSV, }) {
    const intl = useIntl();
    const detailMessage = getPartialDataWarningMessage(limitBreaks, intl);
    useEffect(() => {
        setIsOpen(true);
    }, [executionResult]);
    const [isOpen, setIsOpen] = useState(true);
    const handleCloseOverlay = () => {
        setIsOpen(false);
    };
    const exportFullResult = (event) => {
        event.preventDefault();
        onExportRawCSV?.();
    };
    return (_jsx(_Fragment, { children: isOpen && isLoading === false ? (_jsx(DialogBase, { className: className, onMouseUp: noop, submitOnEnterKey: false, isModal: false, autofocusOnOpen: false, children: _jsx(WidgetNotice, { dataTestId: "partial-data-warning", type: "warning", message: _jsx(FormattedMessage, { id: "partial_data_warning.title" }), detail: _jsx(FormattedMessage, { ...detailMessage }), detailAction: isExportRawVisible && !isEditMode ? (_jsx(UiLink, { isDisabled: isExporting, variant: "primary", href: "#", onClick: exportFullResult, children: _jsx(FormattedMessage, { id: "partial_data_warning.export_raw" }) })) : undefined, expandLabel: _jsx(FormattedMessage, { id: "partial_data_warning.show_details" }), collapseLabel: _jsx(FormattedMessage, { id: "partial_data_warning.hide_details" }), onClose: handleCloseOverlay, closeButtonLabel: intl.formatMessage(defineMessage({ id: "partial_data_warning.close" })) }) })) : null }));
}
