import { jsx as _jsx } from "react/jsx-runtime";
// (C) 2019-2026 GoodData Corporation
import { useCallback } from "react";
import { useToastMessage } from "@gooddata/sdk-ui-kit";
import { messages } from "../../../locales.js";
import { useDashboardDispatch, useDashboardSelector } from "../../../model/react/DashboardStoreProvider.js";
import { uiActions } from "../../../model/store/ui/index.js";
import { selectIsSaveAsDialogOpen } from "../../../model/store/ui/uiSelectors.js";
import { SaveAsDialogRenderer } from "./SaveAsDialogRenderer.js";
import { useSaveAs } from "./useSaveAs.js";
/**
 * @internal
 */
export function useSaveAsDialogProps() {
    const { addSuccess, addError } = useToastMessage();
    const dispatch = useDashboardDispatch();
    const closeSaveAsDialog = useCallback(() => dispatch(uiActions.closeSaveAsDialog()), [dispatch]);
    const isSaveAsDialogOpen = useDashboardSelector(selectIsSaveAsDialogOpen);
    const onSaveAsError = useCallback(() => {
        closeSaveAsDialog();
        addError(messages.messagesDashboardSaveFailed, { id: "message_dashboard_save_failed" });
    }, [closeSaveAsDialog, addError]);
    const onSaveAsSuccess = useCallback(() => {
        closeSaveAsDialog();
        addSuccess(messages.messagesDashboardSaveSuccess, { id: "message_dashboard_save_success" });
    }, [closeSaveAsDialog, addSuccess]);
    const onSaveAsCancel = useCallback(() => {
        closeSaveAsDialog();
    }, [closeSaveAsDialog]);
    return {
        isVisible: isSaveAsDialogOpen,
        onCancel: onSaveAsCancel,
        onError: onSaveAsError,
        onSuccess: onSaveAsSuccess,
    };
}
/**
 * @alpha
 */
export function DefaultSaveAsDialog({ onSubmit, onCancel, onError, isVisible, onSuccess, }) {
    const { locale, dashboardTitle, isKpiWidgetEnabled, isDashboardSaving, isDashboardLoaded, handleSaveAs, isInEditMode, } = useSaveAs({ onSubmit, onSubmitSuccess: onSuccess, onSubmitError: onError });
    if (!isVisible) {
        return null;
    }
    return (_jsx(SaveAsDialogRenderer, { locale: locale, dashboardTitle: dashboardTitle, isKpiWidgetEnabled: isKpiWidgetEnabled, isDashboardLoaded: isDashboardLoaded, isDashboardSaving: isDashboardSaving, isInEditMode: isInEditMode, onSubmit: handleSaveAs, onCancel: onCancel }));
}
//# sourceMappingURL=index.js.map