Liferay.Loader.define("app-builder-web@1.0.76/js/pages/apps/edit/EditApp.es", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/layout', 'frontend-js-react-web$react', '../../../components/control-menu/ControlMenu.es', '../../../components/loading/Loading.es', '../../../components/multi-step-nav/MultiStepNav.es', '../../../hooks/useDataDefinition.es', '../../../hooks/useQuery.es', '../../../utils/client.es', './DeployApp.es', './EditAppBody.es', './EditAppContext.es', './EditAppFooter.es', './EditAppHeader.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 _layout = _interopRequireDefault(require("@frontend-taglib-clay$clayui/layout"));

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

    var _ControlMenu = _interopRequireDefault(require("../../../components/control-menu/ControlMenu.es"));

    var _Loading = require("../../../components/loading/Loading.es");

    var _MultiStepNav = _interopRequireDefault(require("../../../components/multi-step-nav/MultiStepNav.es"));

    var _useDataDefinition2 = _interopRequireDefault(require("../../../hooks/useDataDefinition.es"));

    var _useQuery = require("../../../hooks/useQuery.es");

    var _client = require("../../../utils/client.es");

    var _DeployApp = _interopRequireDefault(require("./DeployApp.es"));

    var _EditAppBody = _interopRequireDefault(require("./EditAppBody.es"));

    var _EditAppContext = _interopRequireWildcard(require("./EditAppContext.es"));

    var _EditAppFooter = _interopRequireDefault(require("./EditAppFooter.es"));

    var _EditAppHeader = _interopRequireDefault(require("./EditAppHeader.es"));

    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 _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 _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 = function _default(_ref) {
      var search = _ref.location.search,
          _ref$match$params = _ref.match.params,
          appId = _ref$match$params.appId,
          dataDefinitionId = _ref$match$params.dataDefinitionId,
          scope = _ref.scope;

      var _useDataDefinition = (0, _useDataDefinition2.default)(dataDefinitionId),
          _useDataDefinition$av = _useDataDefinition.availableLanguageIds,
          availableLanguageIds = _useDataDefinition$av === void 0 ? [] : _useDataDefinition$av,
          _useDataDefinition$de = _useDataDefinition.defaultLanguageId,
          defaultLanguageId = _useDataDefinition$de === void 0 ? '' : _useDataDefinition$de;

      var _useState = (0, _react.useState)(0),
          _useState2 = _slicedToArray(_useState, 2),
          currentStep = _useState2[0],
          setCurrentStep = _useState2[1];

      var _useState3 = (0, _react.useState)(false),
          _useState4 = _slicedToArray(_useState3, 2),
          isLoading = _useState4[0],
          setLoading = _useState4[1];

      var _useState5 = (0, _react.useState)(''),
          _useState6 = _slicedToArray(_useState5, 2),
          editingLanguageId = _useState6[0],
          setEditingLanguageId = _useState6[1];

      var _useReducer = (0, _react.useReducer)(_EditAppContext.reducer, {
        app: {
          active: true,
          appDeployments: [],
          dataLayoutId: null,
          dataListViewId: null,
          name: _defineProperty({}, defaultLanguageId, ''),
          scope: scope
        }
      }),
          _useReducer2 = _slicedToArray(_useReducer, 2),
          state = _useReducer2[0],
          dispatch = _useReducer2[1];

      var _toQuery = (0, _useQuery.toQuery)(search, {
        backUrl: '../'
      }),
          backUrl = _toQuery.backUrl;

      (0, _react.useEffect)(function () {
        if (!editingLanguageId) {
          setEditingLanguageId(defaultLanguageId);
        }
      }, [defaultLanguageId, editingLanguageId]);
      (0, _react.useEffect)(function () {
        if (appId) {
          setLoading(true);
          (0, _client.getItem)("/o/app-builder/v1.0/apps/".concat(appId)).then(function (app) {
            dispatch({
              app: app,
              type: _EditAppContext.UPDATE_APP
            });
            setLoading(false);
          }).catch(function (_) {
            return setLoading(false);
          });
        }
      }, [appId]);
      var title = Liferay.Language.get('new-app');

      if (appId) {
        title = Liferay.Language.get('edit-app');
      }

      var getEmptyState = function getEmptyState(description, title) {
        return {
          description: description,
          title: title
        };
      };

      return (/*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_ControlMenu.default, {
          backURL: backUrl,
          title: title
        }), /*#__PURE__*/_react.default.createElement(_Loading.Loading, {
          isLoading: isLoading
        }, /*#__PURE__*/_react.default.createElement(_EditAppContext.default.Provider, {
          value: {
            dispatch: dispatch,
            state: state
          }
        }, /*#__PURE__*/_react.default.createElement(_layout.default.ContainerFluid, {
          className: "mt-4",
          size: "lg"
        }, /*#__PURE__*/_react.default.createElement("div", {
          className: "card card-root mb-0 shadowless-card"
        }, /*#__PURE__*/_react.default.createElement(_EditAppHeader.default, {
          availableLanguageIds: availableLanguageIds,
          defaultLanguageId: defaultLanguageId,
          editingLanguageId: editingLanguageId,
          onEditingLanguageIdChange: function onEditingLanguageIdChange(editingLanguageId) {
            setEditingLanguageId(editingLanguageId);
          }
        }), /*#__PURE__*/_react.default.createElement("div", {
          className: "card-body p-0 shadowless-card-body"
        }, /*#__PURE__*/_react.default.createElement(_layout.default.Row, null, /*#__PURE__*/_react.default.createElement(_layout.default.Col, null, /*#__PURE__*/_react.default.createElement(_MultiStepNav.default, {
          currentStep: currentStep,
          steps: ['1', '2', '3']
        }))), currentStep == 0 && /*#__PURE__*/_react.default.createElement(_EditAppBody.default, {
          defaultLanguageId: defaultLanguageId,
          emptyState: getEmptyState(Liferay.Language.get('create-one-or-more-forms-to-display-the-data-held-in-your-data-object'), Liferay.Language.get('there-are-no-form-views-yet')),
          endpoint: "/o/data-engine/v2.0/data-definitions/".concat(dataDefinitionId, "/data-layouts"),
          itemType: "DATA_LAYOUT",
          title: Liferay.Language.get('select-a-form-view')
        }), currentStep == 1 && /*#__PURE__*/_react.default.createElement(_EditAppBody.default, {
          defaultLanguageId: defaultLanguageId,
          emptyState: getEmptyState(Liferay.Language.get('create-one-or-more-tables-to-display-the-data-held-in-your-data-object'), Liferay.Language.get('there-are-no-table-views-yet')),
          endpoint: "/o/data-engine/v2.0/data-definitions/".concat(dataDefinitionId, "/data-list-views"),
          itemType: "DATA_LIST_VIEW",
          title: Liferay.Language.get('select-a-table-view')
        }), currentStep == 2 && /*#__PURE__*/_react.default.createElement(_DeployApp.default, null)), /*#__PURE__*/_react.default.createElement("h4", {
          className: "card-divider"
        }), /*#__PURE__*/_react.default.createElement(_EditAppFooter.default, {
          currentStep: currentStep,
          defaultLanguageId: defaultLanguageId,
          editingLanguageId: editingLanguageId,
          onCurrentStepChange: function onCurrentStepChange(step) {
            setCurrentStep(step);
          }
        }))))))
      );
    };

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