import { focusManager, onlineManager as defaultOnlineManager, QueryCache, } from 'react-query/core';
import { configure } from 'mobx';
import { WixPatternsContainer, } from './WixPatternsContainer';
import { createBrowserHistory } from 'history';
import { PartialWindowMock } from '../mocks/PartialWindowMock';
import debounce from 'lodash/debounce';
import throttle from 'lodash/throttle';
import { partialLodashMock } from '../mocks/partialLodashMock';
import { isJestExists, isTestEnvironment } from '../test-utils/jest';
configure({
    isolateGlobalState: true,
    computedRequiresReaction: process.env.NODE_ENV === 'development',
    disableErrorBoundaries: process.env.NODE_ENV !== 'production' &&
        typeof process !== 'undefined' &&
        process.env.DISABLE_ERROR_BOUNDARIES === 'true',
});
const defaultQueryCache = new QueryCache();
const patchesCache = new Map();
export function buildWixPatternsContainer(wixPatternsEssentials, { containerOverrides, initialProps, localCache, contextType, layoutType, useRelativeSidePanel, } = {}) {
    const { errorMonitor, httpClient, createEssentials, createComponentSettings, useTranslation, Trans, useExperiments, environment, environmentBI, showToast, experiments, errorHandler, onNavigation, getHostContainer, onSidePanelOpen, closeSidePanel, history, user, queryCache = defaultQueryCache, onlineManager = defaultOnlineManager, usePageLocation, navigateTo, onBeforeUnload, onLayerStateChange, openMediaManager, biLogger, } = wixPatternsEssentials;
    return new WixPatternsContainer({
        initialProps,
        errorMonitor,
        httpClient,
        onlineManager,
        focusManager,
        layoutType,
        useRelativeSidePanel,
        createEssentials,
        contextType,
        createComponentSettings,
        history: process.env.NODE_ENV === 'test'
            ? require('history').createMemoryHistory()
            : history ?? createBrowserHistory(),
        experiments,
        biLogger,
        useTranslation,
        Trans,
        useExperiments,
        environment,
        environmentBI,
        errorHandler,
        user,
        showToast,
        usePageLocation,
        navigateTo,
        onNavigation,
        onBeforeUnload,
        onLayerStateChange,
        openMediaManager,
        getHostContainer,
        onSidePanelOpen,
        closeSidePanel,
        queryCache: process.env.NODE_ENV === 'test' || localCache
            ? new QueryCache()
            : queryCache,
        patchesCache: process.env.NODE_ENV === 'test' ? new Map() : patchesCache,
        window: process.env.NODE_ENV === 'test'
            ? new PartialWindowMock()
            : {
                matchMedia: (...args) => window.matchMedia(...args),
                location: window.location,
                download: (uri, saveAs) => {
                    const link = document.createElement('a');
                    link.href = uri;
                    if (saveAs) {
                        link.download = saveAs;
                    }
                    document.body.appendChild(link);
                    link.click();
                    document.body.removeChild(link);
                },
                close: window.close,
            },
        lodash: isTestEnvironment() && isJestExists() && jest.isMockFunction(setTimeout)
            ? partialLodashMock()
            : { debounce, throttle },
        ...containerOverrides,
    });
}
//# sourceMappingURL=buildWixPatternsContainer.js.map