Liferay.Loader.define("layout-content-page-editor-web@2.0.157/page_editor/app/components/App", ['module', 'exports', 'require', 'frontend-js-react-web$prop-types', 'frontend-js-react-web$react', '../../plugins/page-design-options/hooks/useStyleBook', '../actions/types', '../config/index', '../reducers/index', '../selectors/selectSegmentsExperienceId', '../store/index', '../utils/dragAndDrop/useDragAndDrop', './CollectionActiveItemContext', './Controls', './DragPreview', './LayoutViewport', './ShortcutManager', './Sidebar', './Toolbar', './URLParser', './WidgetsContext', './fragment-content/EditableProcessorContext'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    function _typeof(obj) {
      "@babel/helpers - typeof";
      if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
        _typeof = function _typeof(obj) {
          return typeof obj;
        };
      } else {
        _typeof = function _typeof(obj) {
          return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
        };
      }return _typeof(obj);
    }

    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.default = App;

    var _propTypes = _interopRequireDefault(require("frontend-js-react-web$prop-types"));

    var _react = _interopRequireWildcard(require("frontend-js-react-web$react"));

    var _useStyleBook = require("../../plugins/page-design-options/hooks/useStyleBook");

    var _types = require("../actions/types");

    var _index = require("../config/index");

    var _index2 = require("../reducers/index");

    var _selectSegmentsExperienceId = _interopRequireDefault(require("../selectors/selectSegmentsExperienceId"));

    var _index3 = require("../store/index");

    var _useDragAndDrop = require("../utils/dragAndDrop/useDragAndDrop");

    var _CollectionActiveItemContext = require("./CollectionActiveItemContext");

    var _Controls = require("./Controls");

    var _DragPreview = _interopRequireDefault(require("./DragPreview"));

    var _LayoutViewport = _interopRequireDefault(require("./LayoutViewport"));

    var _ShortcutManager = _interopRequireDefault(require("./ShortcutManager"));

    var _Sidebar = _interopRequireDefault(require("./Sidebar"));

    var _Toolbar = _interopRequireDefault(require("./Toolbar"));

    var _URLParser = _interopRequireDefault(require("./URLParser"));

    var _WidgetsContext = require("./WidgetsContext");

    var _EditableProcessorContext = require("./fragment-content/EditableProcessorContext");

    function _getRequireWildcardCache() {
      if (typeof WeakMap !== "function") return null;var cache = new WeakMap();_getRequireWildcardCache = function _getRequireWildcardCache() {
        return cache;
      };return cache;
    }

    function _interopRequireWildcard(obj) {
      if (obj && obj.__esModule) {
        return obj;
      }if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") {
        return { default: obj };
      }var cache = _getRequireWildcardCache();if (cache && cache.has(obj)) {
        return cache.get(obj);
      }var newObj = {};var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var key in obj) {
        if (Object.prototype.hasOwnProperty.call(obj, key)) {
          var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;if (desc && (desc.get || desc.set)) {
            Object.defineProperty(newObj, key, desc);
          } else {
            newObj[key] = obj[key];
          }
        }
      }newObj.default = obj;if (cache) {
        cache.set(obj, newObj);
      }return newObj;
    }

    function _interopRequireDefault(obj) {
      return obj && obj.__esModule ? obj : { default: obj };
    }

    function _slicedToArray(arr, i) {
      return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
    }

    function _nonIterableRest() {
      throw new TypeError("Invalid attempt to destructure non-iterable instance");
    }

    function _iterableToArrayLimit(arr, i) {
      if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) {
        return;
      }var _arr = [];var _n = true;var _d = false;var _e = undefined;try {
        for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
          _arr.push(_s.value);if (i && _arr.length === i) break;
        }
      } catch (err) {
        _d = true;_e = err;
      } finally {
        try {
          if (!_n && _i["return"] != null) _i["return"]();
        } finally {
          if (_d) throw _e;
        }
      }return _arr;
    }

    function _arrayWithHoles(arr) {
      if (Array.isArray(arr)) return arr;
    }

    var DEFAULT_SESSION_LENGTH = 60 * 1000;

    function App(_ref) {
      var state = _ref.state;
      var initialState = (0, _index2.reducer)(state, {
        type: _types.INIT
      });
      (0, _react.useEffect)(function () {
        if (Liferay.Session && _index.config.autoExtendSessionEnabled) {
          var sessionLength = Liferay.Session.get('sessionLength') || DEFAULT_SESSION_LENGTH;
          var interval = setInterval(function () {
            Liferay.Session.extend();
          }, sessionLength / 2);
          return function () {
            return clearInterval(interval);
          };
        }
      }, []);
      return (/*#__PURE__*/_react.default.createElement(_index3.StoreContextProvider, {
          initialState: initialState,
          reducer: _index2.reducer
        }, /*#__PURE__*/_react.default.createElement(BackURL, null), /*#__PURE__*/_react.default.createElement(LanguageDirection, null), /*#__PURE__*/_react.default.createElement(_URLParser.default, null), /*#__PURE__*/_react.default.createElement(_Controls.ControlsProvider, null, /*#__PURE__*/_react.default.createElement(_CollectionActiveItemContext.CollectionActiveItemContextProvider, null, /*#__PURE__*/_react.default.createElement(_useDragAndDrop.DragAndDropContextProvider, null, /*#__PURE__*/_react.default.createElement(_EditableProcessorContext.EditableProcessorContextProvider, null, /*#__PURE__*/_react.default.createElement(_WidgetsContext.WidgetsContextProvider, null, /*#__PURE__*/_react.default.createElement(_DragPreview.default, null), /*#__PURE__*/_react.default.createElement(_Toolbar.default, null), /*#__PURE__*/_react.default.createElement(_LayoutViewport.default, null), /*#__PURE__*/_react.default.createElement(_ShortcutManager.default, null), /*#__PURE__*/_react.default.createElement(_useStyleBook.StyleBookContextProvider, null, /*#__PURE__*/_react.default.createElement(_Sidebar.default, null))))))))
      );
    }

    var BackURL = function BackURL() {
      var _useMemo = (0, _react.useMemo)(function () {
        var backLinkElement = document.querySelector('.lfr-back-link');

        try {
          return [backLinkElement, new URL(backLinkElement === null || backLinkElement === void 0 ? void 0 : backLinkElement.href)];
        } catch (error) {
          return [];
        }
      }, []),
          _useMemo2 = _slicedToArray(_useMemo, 2),
          backLinkElement = _useMemo2[0],
          backLinkURL = _useMemo2[1];

      var segmentsExperienceId = (0, _index3.useSelector)(_selectSegmentsExperienceId.default);
      (0, _react.useEffect)(function () {
        if (backLinkElement && backLinkURL && segmentsExperienceId) {
          backLinkURL.searchParams.set('segmentsExperienceId', segmentsExperienceId);
          backLinkElement.href = backLinkURL.toString();
          var currentURL = new URL(window.location.href);

          if (currentURL.searchParams.has('p_l_back_url')) {
            currentURL.searchParams.set('p_l_back_url', backLinkURL.toString());
            window.history.replaceState(null, document.title, currentURL.toString());
          }
        }
      }, [backLinkElement, backLinkURL, segmentsExperienceId]);
      return null;
    };

    var LanguageDirection = function LanguageDirection() {
      var languageId = (0, _index3.useSelector)(function (state) {
        return state.languageId;
      });
      (0, _react.useEffect)(function () {
        var currentLanguageDirection = _index.config.languageDirection[languageId];
        var wrapper = document.getElementById('wrapper');

        if (wrapper) {
          wrapper.dir = currentLanguageDirection;
          wrapper.lang = languageId;
        }
      }, [languageId]);
      return null;
    };
    //# sourceMappingURL=App.js.map
  }
});
//# sourceMappingURL=App.js.map