"use strict";

exports.__esModule = true;
exports.PageWrapperBase = PageWrapperBase;
var _react = _interopRequireWildcard(require("react"));
var _react2 = require("@wix/bex-utils/react");
var _react3 = require("@wix/bex-core/react");
var _bexCore = require("@wix/bex-core");
var _mobx = require("mobx");
var _designSystem = require("@wix/design-system");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/PageWrapper/PageWrapperBase.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 PageWrapperBase(props) {
  const {
    pageState,
    children
  } = props;
  const [state] = (0, _react.useState)(() => pageState ?? new _bexCore.PageState());
  const {
    modalsContainerRef,
    stackingRootRef,
    _sidePanelOpen
  } = state;
  const sidePanelOpen = (0, _react2.useReactive)(_sidePanelOpen);
  const {
    environment,
    useRelativeSidePanel,
    isMobile
  } = (0, _react3.useWixPatternsContainer)();
  const pageAndModalsRootStyle = (0, _react.useMemo)(() => ({
    position: 'relative',
    width: sidePanelOpen ? `calc(100% - ${_bexCore.SidePanelWidth}px)` : '100%',
    height: '100%',
    transition: 'width 0.4s ease 0s',
    zIndex: 1
  }), [sidePanelOpen]);
  const rootStyle = (0, _react.useMemo)(() => ({
    position: 'relative',
    width: '100%',
    height: '100%',
    overflow: useRelativeSidePanel ? 'hidden' : undefined
  }), []);
  const modalsContainerStyle = (0, _react.useMemo)(() => ({
    position: 'absolute',
    zIndex: 1
  }), []);
  let child = /*#__PURE__*/_react.default.createElement(_react3.PageContextProvider, {
    value: state,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 55,
      columnNumber: 5
    }
  }, /*#__PURE__*/_react.default.createElement("div", {
    "data-wix-patterns": true,
    style: rootStyle,
    "data-hook": "cairo-root-stacking",
    ref: el => {
      stackingRootRef.current = el;
    },
    lang: environment.language,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 56,
      columnNumber: 7
    }
  }, /*#__PURE__*/_react.default.createElement("div", {
    style: pageAndModalsRootStyle,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 65,
      columnNumber: 9
    }
  }, children), /*#__PURE__*/_react.default.createElement("div", {
    "data-hook": "modals-container",
    ref: el => {
      (0, _mobx.runInAction)(() => {
        modalsContainerRef.current = el;
      });
    },
    style: modalsContainerStyle,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 66,
      columnNumber: 9
    }
  })));
  if (isMobile) {
    child = /*#__PURE__*/_react.default.createElement(_designSystem.WixDesignSystemProvider, {
      mobile: true,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 81,
        columnNumber: 7
      }
    }, child);
  }
  return child;
}
//# sourceMappingURL=PageWrapperBase.js.map