Liferay.Loader.define("data-engine-taglib@2.5.29/data_layout_builder/js/App.es", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/modal', 'frontend-js-react-web$react', 'frontend-js-react-web$react-dnd', 'frontend-js-react-web$react-dnd-html5-backend', './AppContext.es', './AppContextProvider.es', './actions.es', './components/sidebar/MultiPanelSidebar.es', './components/sidebar/initializeSidebarConfig.es', './data-layout-builder/DataLayoutBuilder.es', './data-layout-builder/DataLayoutBuilderContextProvider.es', './drag-and-drop/DragLayer.es'], 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 = void 0;

    var _modal = require("@frontend-taglib-clay$clayui/modal");

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

    var _reactDnd = require("frontend-js-react-web$react-dnd");

    var _reactDndHtml5Backend = require("frontend-js-react-web$react-dnd-html5-backend");

    var _AppContext = _interopRequireDefault(require("./AppContext.es"));

    var _AppContextProvider = _interopRequireDefault(require("./AppContextProvider.es"));

    var _actions = require("./actions.es");

    var _MultiPanelSidebar = _interopRequireDefault(require("./components/sidebar/MultiPanelSidebar.es"));

    var _initializeSidebarConfig = _interopRequireDefault(require("./components/sidebar/initializeSidebarConfig.es"));

    var _DataLayoutBuilder = _interopRequireDefault(require("./data-layout-builder/DataLayoutBuilder.es"));

    var _DataLayoutBuilderContextProvider = _interopRequireDefault(require("./data-layout-builder/DataLayoutBuilderContextProvider.es"));

    var _DragLayer = _interopRequireDefault(require("./drag-and-drop/DragLayer.es"));

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

    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 _toConsumableArray(arr) {
      return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
    }

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

    function _iterableToArray(iter) {
      if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
    }

    function _arrayWithoutHoles(arr) {
      if (Array.isArray(arr)) {
        for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
          arr2[i] = arr[i];
        }return arr2;
      }
    }

    function _extends() {
      _extends = Object.assign || function (target) {
        for (var i = 1; i < arguments.length; i++) {
          var source = arguments[i];for (var key in source) {
            if (Object.prototype.hasOwnProperty.call(source, key)) {
              target[key] = source[key];
            }
          }
        }return target;
      };return _extends.apply(this, arguments);
    }

    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;
    }

    function ownKeys(object, enumerableOnly) {
      var keys = Object.keys(object);if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);if (enumerableOnly) symbols = symbols.filter(function (sym) {
          return Object.getOwnPropertyDescriptor(object, sym).enumerable;
        });keys.push.apply(keys, symbols);
      }return keys;
    }

    function _objectSpread(target) {
      for (var i = 1; i < arguments.length; i++) {
        var source = arguments[i] != null ? arguments[i] : {};if (i % 2) {
          ownKeys(Object(source), true).forEach(function (key) {
            _defineProperty(target, key, source[key]);
          });
        } else if (Object.getOwnPropertyDescriptors) {
          Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
        } else {
          ownKeys(Object(source)).forEach(function (key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
          });
        }
      }return target;
    }

    function _defineProperty(obj, key, value) {
      if (key in obj) {
        Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true });
      } else {
        obj[key] = value;
      }return obj;
    }

    function _objectWithoutProperties(source, excluded) {
      if (source == null) return {};var target = _objectWithoutPropertiesLoose(source, excluded);var key, i;if (Object.getOwnPropertySymbols) {
        var sourceSymbolKeys = Object.getOwnPropertySymbols(source);for (i = 0; i < sourceSymbolKeys.length; i++) {
          key = sourceSymbolKeys[i];if (excluded.indexOf(key) >= 0) continue;if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;target[key] = source[key];
        }
      }return target;
    }

    function _objectWithoutPropertiesLoose(source, excluded) {
      if (source == null) return {};var target = {};var sourceKeys = Object.keys(source);var key, i;for (i = 0; i < sourceKeys.length; i++) {
        key = sourceKeys[i];if (excluded.indexOf(key) >= 0) continue;target[key] = source[key];
      }return target;
    }

    var parseProps = function parseProps(_ref) {
      var dataDefinitionId = _ref.dataDefinitionId,
          dataLayoutId = _ref.dataLayoutId,
          fieldTypesModules = _ref.fieldTypesModules,
          groupId = _ref.groupId,
          props = _objectWithoutProperties(_ref, ["dataDefinitionId", "dataLayoutId", "fieldTypesModules", "groupId"]);

      return _objectSpread(_objectSpread({}, props), {}, {
        dataDefinitionId: Number(dataDefinitionId),
        dataLayoutId: Number(dataLayoutId),
        fieldTypesModules: fieldTypesModules.split(','),
        groupId: Number(groupId)
      });
    };

    var AppContent = function AppContent(_ref2) {
      var dataLayoutBuilder = _ref2.dataLayoutBuilder,
          setChildrenContext = _ref2.setChildrenContext,
          setDataLayoutBuilder = _ref2.setDataLayoutBuilder,
          sidebarConfig = _ref2.sidebarConfig,
          props = _objectWithoutProperties(_ref2, ["dataLayoutBuilder", "setChildrenContext", "setDataLayoutBuilder", "sidebarConfig"]);

      var _useContext = (0, _react.useContext)(_AppContext.default),
          _useContext2 = _slicedToArray(_useContext, 2),
          state = _useContext2[0],
          dispatch = _useContext2[1];

      var panels = sidebarConfig.panels,
          sidebarPanels = sidebarConfig.sidebarPanels,
          sidebarVariant = sidebarConfig.sidebarVariant;
      (0, _react.useEffect)(function () {
        if (dataLayoutBuilder) {
          dataLayoutBuilder.emit('contextUpdated', state);
        }
      }, [dataLayoutBuilder, state]);
      (0, _react.useEffect)(function () {
        if (setChildrenContext) {
          setChildrenContext({
            dataLayoutBuilder: dataLayoutBuilder,
            dispatch: dispatch,
            state: state
          });
        }
      }, [dataLayoutBuilder, dispatch, setChildrenContext, state]);
      (0, _react.useEffect)(function () {
        if (!setChildrenContext) {
          dispatch({
            payload: props,
            type: _actions.UPDATE_APP_PROPS
          });
        } // eslint-disable-next-line react-hooks/exhaustive-deps
      }, [dispatch, setChildrenContext]);
      return (/*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_DataLayoutBuilder.default, _extends({
          appContext: [state, dispatch],
          config: state.config,
          onLoad: setDataLayoutBuilder
        }, parseProps(props))), dataLayoutBuilder && /*#__PURE__*/_react.default.createElement(_DataLayoutBuilderContextProvider.default, {
          dataLayoutBuilder: dataLayoutBuilder
        }, /*#__PURE__*/_react.default.createElement(_MultiPanelSidebar.default, {
          panels: panels,
          sidebarPanels: sidebarPanels,
          variant: sidebarVariant
        }), /*#__PURE__*/_react.default.createElement(_DragLayer.default, null)))
      );
    };

    var App = function App(props) {
      var _parseProps = parseProps(props),
          config = _parseProps.config,
          contentType = _parseProps.contentType,
          dataDefinitionId = _parseProps.dataDefinitionId,
          dataLayoutId = _parseProps.dataLayoutId,
          fieldSetContentType = _parseProps.fieldSetContentType,
          fieldTypesModules = _parseProps.fieldTypesModules,
          groupId = _parseProps.groupId;

      var sidebarConfig = (0, _initializeSidebarConfig.default)(props);

      var _useState = (0, _react.useState)(false),
          _useState2 = _slicedToArray(_useState, 2),
          loaded = _useState2[0],
          setLoaded = _useState2[1];

      var _useState3 = (0, _react.useState)(null),
          _useState4 = _slicedToArray(_useState3, 2),
          dataLayoutBuilder = _useState4[0],
          setDataLayoutBuilder = _useState4[1];

      (0, _react.useEffect)(function () {
        var _Liferay$Loader;

        (_Liferay$Loader = Liferay.Loader).require.apply(_Liferay$Loader, _toConsumableArray(fieldTypesModules).concat([function () {
          setLoaded(true);
        }]));
      }, [fieldTypesModules]);
      return (/*#__PURE__*/_react.default.createElement(_reactDnd.DndProvider, {
          backend: _reactDndHtml5Backend.HTML5Backend
        }, /*#__PURE__*/_react.default.createElement(_modal.ClayModalProvider, null, loaded && /*#__PURE__*/_react.default.createElement(_AppContextProvider.default, {
          config: config,
          contentType: contentType,
          dataDefinitionId: dataDefinitionId,
          dataLayoutBuilder: dataLayoutBuilder,
          dataLayoutId: dataLayoutId,
          fieldSetContentType: fieldSetContentType,
          groupId: groupId
        }, /*#__PURE__*/_react.default.createElement(AppContent, _extends({
          dataLayoutBuilder: dataLayoutBuilder,
          setDataLayoutBuilder: setDataLayoutBuilder,
          sidebarConfig: sidebarConfig
        }, props)))))
      );
    };

    var _default = App;
    exports.default = _default;
    //# sourceMappingURL=App.es.js.map
  }
});
//# sourceMappingURL=App.es.js.map