"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.WixPatternsEssentialsTestProvider = WixPatternsEssentialsTestProvider;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _react = _interopRequireWildcard(require("react"));
var _react2 = require("@wix/fe-essentials/react");
var _dataCapsule = require("@wix/fe-essentials/data-capsule");
var _providers = require("../providers");
var _ExtensionWidget = _interopRequireDefault(require("./ExtensionWidget"));
var _wixUiIconsCommon = require("@wix/wix-ui-icons-common");
var _errorHandler = require("@wix/fe-essentials/error-handler");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/test-utils/WixPatternsEssentialsTestProvider.tsx";
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
function WixPatternsEssentialsTestProvider(props) {
  const {
    children,
    overrides,
    defaultExperiments,
    ...rest
  } = props;
  const {
    errorMonitor,
    httpClient,
    environment,
    createChildEssentials,
    experiments,
    biLoggerFactory
  } = (0, _react2.useEssentials)();
  const [value] = (0, _react.useState)(() => ({
    createEssentials: options => {
      var _options$experiments, _URLSearchParams$get, _URLSearchParams$get2;
      return createChildEssentials({
        ...options,
        experiments: options.experiments && 'scopes' in options.experiments && ((_options$experiments = options.experiments) == null ? void 0 : _options$experiments.scopes[0]) === 'cairo' ? {
          bag: {
            ...(((_URLSearchParams$get = new URLSearchParams(window.location.search).get('id')) == null ? void 0 : _URLSearchParams$get.includes('responsivetoolbar')) && {
              'specs.cairo.EnableResponsiveToolbar11420': 'true'
            }),
            ...defaultExperiments,
            ...Object.fromEntries(((_URLSearchParams$get2 = new URLSearchParams(window.location.search).get('experiments')) == null || (_URLSearchParams$get2 = _URLSearchParams$get2.split(',')) == null ? void 0 : _URLSearchParams$get2.map(e => {
              const [spec = '', enabled = 'true'] = e.split(':');
              return [spec, enabled];
            })) ?? [])
          }
        } : options.experiments
      });
    },
    createComponentSettings: () => () => new _dataCapsule.DataCapsule({
      namespace: '',
      scope: 'cairo-test',
      strategy: new _dataCapsule.AppSettingsStorageStrategy({
        host: 'other',
        httpClient
      })
    }),
    errorMonitor,
    errorHandler: new _errorHandler.ErrorHandler({
      biLoggerOrFactory: biLoggerFactory,
      createErrorMonitor: options => createChildEssentials({
        errorMonitor: options
      }).errorMonitor,
      environment,
      createI18n: options => createChildEssentials({
        i18n: options
      }).i18n
    }).v2,
    useTranslation: _react2.useTranslation,
    Trans: _react2.Trans,
    useExperiments: () => (0, _react2.useExperiments)({
      readOnly: true
    }),
    httpClient,
    experiments,
    ...overrides,
    user: {
      permissions: [],
      ...(overrides == null ? void 0 : overrides.user)
    },
    environment: {
      ...environment,
      componentId: [environment.artifactId, 'cairo-test-component'].join('.'),
      language: 'en-US',
      ...(overrides == null ? void 0 : overrides.environment)
    },
    environmentBI: {
      artifactId: environment.artifactId
    },
    getHostContainer: _ => ({
      getExtensions: () => Promise.resolve([{
        title: 'Extension',
        componentId: '',
        Extension: props => /*#__PURE__*/_react.default.createElement(_ExtensionWidget.default, (0, _extends2.default)({}, props, {
          __self: this,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 114,
            columnNumber: 42
          }
        })),
        menuItem: {
          IconComponent: _wixUiIconsCommon.Edit,
          structuredAction: () => alert('action')
        }
      }])
    })
  }));
  return /*#__PURE__*/_react.default.createElement(_providers.CairoProvider, (0, _extends2.default)({
    localCache: true,
    value: value
  }, rest, {
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 126,
      columnNumber: 5
    }
  }), children);
}
//# sourceMappingURL=WixPatternsEssentialsTestProvider.js.map