// (C) 2021-2026 GoodData Corporation
import { useIntl } from "react-intl";
import { ToastsCenterContext } from "./context.js";
/**
 * @internal
 */
export const useToastMessage = () => {
    const { addMessage, removeMessage, removeAllMessages } = ToastsCenterContext.useContextStoreValues([
        "addMessage",
        "removeMessage",
        "removeAllMessages",
    ]);
    const intl = useIntl();
    const addMessageBase = (type) => (message, options) => {
        if (options?.values) {
            return addMessage({ ...options, type, node: intl.formatMessage(message, options.values) });
        }
        return addMessage({ ...options, type, text: intl.formatMessage(message) });
    };
    const addSuccess = addMessageBase("success");
    const addProgress = addMessageBase("progress");
    const addWarning = addMessageBase("warning");
    const addError = addMessageBase("error");
    return {
        addSuccess,
        addProgress,
        addWarning,
        addError,
        removeMessage,
        removeAllMessages,
    };
};
