"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.buildWixPatternsContainer = buildWixPatternsContainer;
var _core = require("react-query/core");
var _mobx = require("mobx");
var _WixPatternsContainer = require("./WixPatternsContainer");
var _history = require("history");
var _PartialWindowMock = require("../mocks/PartialWindowMock");
var _debounce = _interopRequireDefault(require("lodash/debounce"));
var _throttle = _interopRequireDefault(require("lodash/throttle"));
var _partialLodashMock = require("../mocks/partialLodashMock");
var _jest = require("../test-utils/jest");
(0, _mobx.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 _core.QueryCache();
const patchesCache = new Map();
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 = _core.onlineManager,
    usePageLocation,
    navigateTo,
    onBeforeUnload,
    onLayerStateChange,
    openMediaManager,
    biLogger
  } = wixPatternsEssentials;
  return new _WixPatternsContainer.WixPatternsContainer({
    initialProps,
    errorMonitor,
    httpClient,
    onlineManager,
    focusManager: _core.focusManager,
    layoutType,
    useRelativeSidePanel,
    createEssentials,
    contextType,
    createComponentSettings,
    history: process.env.NODE_ENV === 'test' ? require('history').createMemoryHistory() : history ?? (0, _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 _core.QueryCache() : queryCache,
    patchesCache: process.env.NODE_ENV === 'test' ? new Map() : patchesCache,
    window: process.env.NODE_ENV === 'test' ? new _PartialWindowMock.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: (0, _jest.isTestEnvironment)() && (0, _jest.isJestExists)() && jest.isMockFunction(setTimeout) ? (0, _partialLodashMock.partialLodashMock)() : {
      debounce: _debounce.default,
      throttle: _throttle.default
    },
    ...containerOverrides
  });
}
//# sourceMappingURL=buildWixPatternsContainer.js.map