import '../../../../../node_modules/preact/compat/dist/compat.module.mjs';
import { useToast } from '../shared/components/Toast.mjs';
import '../shared/components/Typography.mjs';
import { useCallback as T } from '../../../../../node_modules/preact/hooks/dist/hooks.module.mjs';

const useMutateWithToast = (callback)=>{
    const { openToast } = useToast();
    const mutate = T(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
