Liferay.Loader.define("app-builder-workflow-web@1.0.40/js/pages/apps/edit/EditAppToolbar.es", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/badge', '@frontend-taglib-clay$clayui/button', '@frontend-taglib-clay$clayui/tooltip', 'app-builder-web/js/AppContext.es', 'app-builder-web/js/components/upper-toolbar/UpperToolbar.es', 'app-builder-web/js/hooks/useDeployApp.es', 'app-builder-web/js/pages/apps/edit/EditAppContext.es', 'app-builder-web/js/utils/toast.es', 'data-engine-taglib', 'frontend-js-react-web$react', '../../../../css/EditApp.scss', './utils.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 = EditAppToolbar;

    var _badge = _interopRequireDefault(require("@frontend-taglib-clay$clayui/badge"));

    var _button = _interopRequireWildcard(require("@frontend-taglib-clay$clayui/button"));

    var _tooltip = require("@frontend-taglib-clay$clayui/tooltip");

    var _AppContext = require("app-builder-web/js/AppContext.es");

    var _UpperToolbar = _interopRequireWildcard(require("app-builder-web/js/components/upper-toolbar/UpperToolbar.es"));

    var _useDeployApp2 = _interopRequireDefault(require("app-builder-web/js/hooks/useDeployApp.es"));

    var _EditAppContext = _interopRequireWildcard(require("app-builder-web/js/pages/apps/edit/EditAppContext.es"));

    var _toast = require("app-builder-web/js/utils/toast.es");

    var _dataEngineTaglib = require("data-engine-taglib");

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

    require("../../../../css/EditApp.scss");

    var _utils = require("./utils.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 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 _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 EditAppToolbar(_ref) {
      var _app$version;

      var isSaving = _ref.isSaving,
          onCancel = _ref.onCancel,
          onSave = _ref.onSave;

      var _useContext = (0, _react.useContext)(_EditAppContext.default),
          appId = _useContext.appId,
          config = _useContext.config,
          dispatch = _useContext.dispatch,
          setAppChangesModalVisible = _useContext.setAppChangesModalVisible,
          setDeployModalVisible = _useContext.setDeployModalVisible,
          app = _useContext.state.app;

      var _useContext2 = (0, _react.useContext)(_AppContext.AppContext),
          showTranslationManager = _useContext2.showTranslationManager;

      var _config$dataObject = config.dataObject,
          availableLanguageIds = _config$dataObject.availableLanguageIds,
          defaultLanguageId = _config$dataObject.defaultLanguageId;

      var _useDeployApp = (0, _useDeployApp2.default)(),
          undeployApp = _useDeployApp.undeployApp;

      var _useState = (0, _react.useState)(defaultLanguageId),
          _useState2 = _slicedToArray(_useState, 2),
          editingLanguageId = _useState2[0],
          setEditingLanguageId = _useState2[1];

      var appName = app.name[editingLanguageId];
      var availableLanguages = availableLanguageIds.reduce(function (languages, languageId) {
        return _objectSpread(_objectSpread({}, languages), {}, _defineProperty({}, languageId, languageId));
      }, {});

      var onChangeEditingLanguageId = (0, _react.useCallback)(function (newEditingLanguageId) {
        setEditingLanguageId(newEditingLanguageId);

        if (!app.name[newEditingLanguageId]) {
          dispatch({
            name: _objectSpread(_objectSpread({}, app.name), {}, _defineProperty({}, newEditingLanguageId, app.name[editingLanguageId])),
            type: _EditAppContext.UPDATE_NAME
          });
        }
      }, [app.name, dispatch, editingLanguageId]);

      (0, _react.useEffect)(function () {
        if (!availableLanguageIds.includes(editingLanguageId)) {
          setEditingLanguageId(defaultLanguageId);
        }

        dispatch({
          name: availableLanguageIds.reduce(function (name, languageId) {
            return _objectSpread(_objectSpread({}, name), {}, _defineProperty({}, languageId, app.name[languageId] || appName));
          }, {}),
          type: _EditAppContext.UPDATE_NAME
        }); // eslint-disable-next-line react-hooks/exhaustive-deps
      }, [availableLanguageIds, defaultLanguageId]);
      var isDisabledSaveButton = !(0, _utils.canDeployApp)(_objectSpread(_objectSpread({}, app), {}, {
        appName: appName
      }), config) || isSaving;
      return (/*#__PURE__*/_react.default.createElement(_UpperToolbar.default, {
          className: "align-items-center"
        }, showTranslationManager && /*#__PURE__*/_react.default.createElement(_dataEngineTaglib.TranslationManager, {
          availableLanguageIds: availableLanguages,
          className: "mr-1",
          defaultLanguageId: defaultLanguageId,
          editingLanguageId: editingLanguageId,
          onEditingLanguageIdChange: onChangeEditingLanguageId,
          translatedLanguageIds: app.name
        }), /*#__PURE__*/_react.default.createElement(_UpperToolbar.UpperToolbarInput, {
          maxLength: 30,
          onChange: function onAppNameChange(_ref2) {
            var target = _ref2.target;
            dispatch({
              name: _objectSpread(_objectSpread({}, app.name), {}, _defineProperty({}, editingLanguageId, target.value)),
              type: _EditAppContext.UPDATE_NAME
            });
          },
          placeholder: Liferay.Language.get('untitled-app'),
          value: appName
        }), /*#__PURE__*/_react.default.createElement(_UpperToolbar.default.Group, null, appId && /*#__PURE__*/_react.default.createElement(_badge.default, {
          className: "text-secondary version-badge",
          displayType: "secondary",
          label: /*#__PURE__*/_react.default.createElement("div", null, "".concat(Liferay.Language.get('version'), ":"), ' ', /*#__PURE__*/_react.default.createElement("span", {
            className: "font-weight-normal text-dark"
          }, (_app$version = app.version) !== null && _app$version !== void 0 ? _app$version : '1.0'))
        }), /*#__PURE__*/_react.default.createElement(_UpperToolbar.default.Button, {
          displayType: "secondary",
          onClick: onCancel
        }, Liferay.Language.get('cancel')), /*#__PURE__*/_react.default.createElement(_UpperToolbar.default.Button, {
          disabled: isDisabledSaveButton,
          displayType: "secondary",
          onClick: function onClickSave() {
            if (appId && (0, _utils.hasConfigBreakChanges)(config)) {
              setAppChangesModalVisible(true);
            } else {
              onSave();
            }
          }
        }, Liferay.Language.get('save')), /*#__PURE__*/_react.default.createElement(_button.default.Group, {
          className: "ml-2"
        }, /*#__PURE__*/_react.default.createElement(_button.default, {
          disabled: !app.active && isDisabledSaveButton,
          displayType: app.active ? 'secondary' : 'primary',
          onClick: app.active ? function onClickUndeploy() {
            undeployApp(_objectSpread(_objectSpread({}, app), {}, {
              appName: appName
            })).then(function () {
              dispatch({
                app: _objectSpread(_objectSpread({}, app), {}, {
                  active: false
                }),
                type: _EditAppContext.UPDATE_APP
              });
            }).catch(function (_ref3) {
              var title = _ref3.title;
              return (0, _toast.errorToast)(title);
            });
          } : function () {
            return setDeployModalVisible(true);
          },
          small: true
        }, app.active ? Liferay.Language.get('undeploy') : Liferay.Language.get('deploy')), app.active && /*#__PURE__*/_react.default.createElement(_tooltip.ClayTooltipProvider, null, /*#__PURE__*/_react.default.createElement(_button.ClayButtonWithIcon, {
          "data-tooltip-align": "bottom",
          "data-tooltip-delay": "0",
          displayType: "secondary",
          onClick: function onClick() {
            return setDeployModalVisible(true);
          },
          small: true,
          symbol: "cog",
          title: Liferay.Language.get('deploy-settings')
        })))))
      );
    }
    //# sourceMappingURL=EditAppToolbar.es.js.map
  }
});
//# sourceMappingURL=EditAppToolbar.es.js.map