import { __rest } from '../../../../_virtual/_tslib.js';
import { TOAST_VARIANT_DEFAULT } from '../constants.js';
import { makeMessageId } from './makeMessageId.js';

const generateMessageFromVariant = (dispatch, providerOptions, methodVariant) => {
    return (message, messageOptions) => {
        const messageOptionsFromProvider = __rest(providerOptions, ["position"]);
        const defaultMessageOption = Object.assign({ variant: methodVariant || TOAST_VARIANT_DEFAULT }, messageOptionsFromProvider);
        const id = makeMessageId();
        dispatch({
            type: 'add',
            message: Object.assign(Object.assign({ id: id, message: message, onClose: () => dispatch({ type: 'remove', messageId: id }) }, defaultMessageOption), messageOptions),
        });
    };
};
const createMessageMethods = (dispatch, providerOptions) => {
    return {
        clear: () => dispatch({ type: 'clear' }),
        custom: generateMessageFromVariant(dispatch, providerOptions),
        error: generateMessageFromVariant(dispatch, providerOptions, 'error'),
        info: generateMessageFromVariant(dispatch, providerOptions, 'info'),
        success: generateMessageFromVariant(dispatch, providerOptions, 'positive'),
        warning: generateMessageFromVariant(dispatch, providerOptions, 'warning'),
    };
};

export { createMessageMethods };
