import { useCallback } from 'react';
import { useToast } from '../shared/components/Toast.mjs';
import '../shared/components/Typography.mjs';

const useMutateWithToast = (callback)=>{
    const { openToast } = useToast();
    const mutate = useCallback(async (properties, { errorMessage } = {})=>{
        try {
            return await callback(properties);
        } catch (e) {
            if (errorMessage) {
                openToast({
                    type: 'error',
                    text: typeof errorMessage === 'function' ? errorMessage(e) : errorMessage
                });
            }
            throw e;
        }
    }, [
        callback,
        openToast
    ]);
    return {
        mutate
    };
};

export { useMutateWithToast };
//# sourceMappingURL=useMutateWithToast.mjs.map
