"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.WixPatternsDashboardBaseProvider = WixPatternsDashboardBaseProvider;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _bexCore = require("@wix/bex-core");
var _react = require("@wix/bex-core/react");
var _wixI18nConfig = require("@wix/bex-utils/@wix/wix-i18n-config");
var _react2 = _interopRequireWildcard(require("react"));
var _providers = require("../providers");
var _getInstanceJwtData = require("./getInstanceJwtData");
var _essentials = require("@wix/essentials");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/dashboard/WixPatternsDashboardBaseProvider.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 WixPatternsDashboardBaseProvider({
  children,
  dashboard,
  environment: {
    locale,
    pageLocation
  },
  essentials,
  ...rest
}) {
  const [value] = (0, _react2.useState)(() => {
    const jwtData = (0, _getInstanceJwtData.getInstanceJwtData)(window.location.search);
    const user = {
      id: jwtData == null ? void 0 : jwtData.uid,
      permissions: ['DATA_EXTENSION_SCHEMA.WRITE']
    };
    const environment = {
      language: locale || 'en',
      artifactId: essentials.environment.artifactId,
      componentId: pageLocation.pageId,
      providerType: 'bm',
      msid: jwtData == null ? void 0 : jwtData.metaSiteId
    };

    // ready doesn't exist in the dashboard-sdk because it's always true. adding it for backwards compatibility
    const experimentsWithReady = {
      ..._essentials.experiments,
      ready: async () => true
    };
    let biLogger;
    try {
      biLogger = _essentials.bi.getLogger();
    } catch (error) {
      console.error(error);
    }
    return {
      useExperiments: () => ({
        ready: true,
        experiments: (0, _bexCore.getExperimentsCompat)({
          experiments: experimentsWithReady
        })
      }),
      experiments: (0, _bexCore.getExperimentsCompat)({
        experiments: experimentsWithReady
      }),
      Trans: _wixI18nConfig.Trans,
      useTranslation: _wixI18nConfig.useTranslation,
      showToast: (0, _bexCore.showToastCompat)(dashboard.showToast),
      usePageLocation: _react.usePageLocation,
      navigateTo: ({
        relativeUrl
      }) => dashboard.navigate({
        pageId: pageLocation.pageId,
        relativeUrl
      }),
      onSidePanelOpen: undefined,
      // missing in dashboard-sdk
      onBeforeUnload: dashboard.onBeforeUnload,
      closeSidePanel: undefined,
      // missing in dashboard-sdk
      getHostContainer: (0, _bexCore.getHostContainerCompat)(dashboard.getDashboardMenuPlugins, dashboard.getDashboardPlugins),
      environment,
      user,
      environmentBI: {
        componentId: environment.componentId
      },
      httpClient: essentials.httpClient,
      errorMonitor: (0, _bexCore.getErrorMonitorCompat)(essentials.asPartial),
      errorHandler: _essentials.errorHandler,
      biLogger,
      createEssentials: options => {
        var _options$experiments;
        return essentials.createChildEssentials({
          ...options,
          experiments: options.experiments && 'scopes' in options.experiments && ((_options$experiments = options.experiments) == null ? void 0 : _options$experiments.scopes[0]) === 'cairo' ? {
            bag: (0, _bexCore.getWixPatternsWindowExperiments)() ?? {}
          } : options.experiments
        });
      },
      createComponentSettings: _bexCore.createAppSettingsCapsule
    };
  });
  return /*#__PURE__*/_react2.default.createElement(_providers.CairoProvider, (0, _extends2.default)({}, rest, {
    value: value,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 119,
      columnNumber: 5
    }
  }), children);
}
//# sourceMappingURL=WixPatternsDashboardBaseProvider.js.map