Liferay.Loader.define("fragment-web@3.0.77/js/FragmentServiceConfiguration", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/button', '@frontend-taglib-clay$clayui/form', '@frontend-taglib-clay$clayui/modal', 'frontend-js-web', 'frontend-js-react-web$react'], 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 = FragmentServiceConfiguration;

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

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

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

    var _frontendJsWeb = require("frontend-js-web");

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

    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 FEEDBACK_MESSAGES = {
      error: {
        cssClass: 'has-error',
        icon: 'exclamation-full',
        text: Liferay.Language.get('the-changes-could-not-be-propagated,-please-try-again')
      },
      success: {
        cssClass: 'has-success',
        icon: 'check-circle-full',
        text: Liferay.Language.get('all-changes-were-propagated')
      }
    };

    function FragmentServiceConfiguration(_ref) {
      var alreadyPropagateContributedFragmentChanges = _ref.alreadyPropagateContributedFragmentChanges,
          namespace = _ref.namespace,
          propagateChanges = _ref.propagateChanges,
          propagateContributedFragmentChanges = _ref.propagateContributedFragmentChanges,
          propagateContributedFragmentEntriesChangesURL = _ref.propagateContributedFragmentEntriesChangesURL;

      var _useState = (0, _react.useState)(alreadyPropagateContributedFragmentChanges),
          _useState2 = _slicedToArray(_useState, 2),
          disablePropagateChangesButton = _useState2[0],
          setDisablePropagateChangesButton = _useState2[1];

      var _useState3 = (0, _react.useState)(propagateContributedFragmentChanges),
          _useState4 = _slicedToArray(_useState3, 2),
          propagateContributedFragmentChangesChecked = _useState4[0],
          setPropagateContributedFragmentChangesChecked = _useState4[1];

      var _useState5 = (0, _react.useState)(propagateChanges),
          _useState6 = _slicedToArray(_useState5, 2),
          propagateChangesChecked = _useState6[0],
          setPropagateChangesChecked = _useState6[1];

      var _useState7 = (0, _react.useState)(null),
          _useState8 = _slicedToArray(_useState7, 2),
          feedbackMessage = _useState8[0],
          setFeedbackMessage = _useState8[1];

      var _useState9 = (0, _react.useState)(false),
          _useState10 = _slicedToArray(_useState9, 2),
          warningModalVisible = _useState10[0],
          setWarningModalVisible = _useState10[1];

      var _useModal = (0, _modal.useModal)({
        onClose: function onClose() {
          return setWarningModalVisible(false);
        }
      }),
          observer = _useModal.observer,
          onClose = _useModal.onClose;

      return (/*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("h3", {
          className: "sheet-subtitle"
        }, Liferay.Language.get('default-fragments')), /*#__PURE__*/_react.default.createElement("p", {
          className: "text-secondary"
        }, Liferay.Language.get('default-fragments-are-provided-by-liferay-and-they-are-part-of-the-product-code.-define-their-behavior')), /*#__PURE__*/_react.default.createElement(_form.ClayCheckbox, {
          defaultChecked: propagateContributedFragmentChanges,
          label: Liferay.Language.get('propagate-contributed-fragment-changes-automatically'),
          name: "".concat(namespace, "propagateContributedFragmentChanges"),
          onChange: function onChange(event) {
            return setPropagateContributedFragmentChangesChecked(event.target.checked);
          }
        }), /*#__PURE__*/_react.default.createElement("div", {
          "aria-hidden": "true",
          className: "form-feedback-group mb-3"
        }, /*#__PURE__*/_react.default.createElement("div", {
          className: "form-text text-weight-normal"
        }, Liferay.Language.get('propagate-contributed-fragment-changes-automatically-description'))), !propagateContributedFragmentChangesChecked && /*#__PURE__*/_react.default.createElement("div", {
          className: "align-items-center d-flex"
        }, /*#__PURE__*/_react.default.createElement(_button.default, {
          className: "mr-3",
          disabled: disablePropagateChangesButton,
          displayType: "secondary",
          onClick: function onClick() {
            return setWarningModalVisible(true);
          }
        }, Liferay.Language.get('propagate-changes')), feedbackMessage && /*#__PURE__*/_react.default.createElement(_form.default.Group, {
          className: "mb-0 ".concat(feedbackMessage.cssClass)
        }, /*#__PURE__*/_react.default.createElement(_form.default.FeedbackGroup, null, /*#__PURE__*/_react.default.createElement(_form.default.FeedbackItem, null, /*#__PURE__*/_react.default.createElement(_form.default.FeedbackIndicator, {
          symbol: feedbackMessage.icon
        }), feedbackMessage.text)))), /*#__PURE__*/_react.default.createElement("h3", {
          className: "mt-3 sheet-subtitle"
        }, Liferay.Language.get('custom-fragments')), /*#__PURE__*/_react.default.createElement("p", {
          className: "text-secondary"
        }, Liferay.Language.get('custom-fragments-are-those-that-are-created-by-the-user.-define-their-behavior')), /*#__PURE__*/_react.default.createElement(_form.ClayCheckbox, {
          defaultChecked: propagateChanges,
          label: Liferay.Language.get('propagate-fragment-changes-automatically'),
          name: "".concat(namespace, "propagateChanges"),
          onChange: function onChange(event) {
            return setPropagateChangesChecked(event.target.checked);
          }
        }), /*#__PURE__*/_react.default.createElement("div", {
          "aria-hidden": "true",
          className: "form-feedback-group"
        }, /*#__PURE__*/_react.default.createElement("div", {
          className: "form-text text-weight-normal"
        }, Liferay.Language.get('propagate-fragment-changes-automatically-description'))), warningModalVisible && /*#__PURE__*/_react.default.createElement(_modal.default, {
          observer: observer,
          role: "alertdialog",
          size: "md",
          status: "warning"
        }, /*#__PURE__*/_react.default.createElement(_modal.default.Header, null, Liferay.Language.get('propagate-changes')), /*#__PURE__*/_react.default.createElement(_modal.default.Body, null, /*#__PURE__*/_react.default.createElement("p", {
          className: "text-secondary"
        }, Liferay.Language.get('please-be-aware-that-if-any-content-creator-is-editing-a-page,-some-changes-may-not-be-saved.-performance-issues-can-also-result-from-this-action')), /*#__PURE__*/_react.default.createElement("p", {
          className: "text-secondary"
        }, Liferay.Language.get('are-you-sure-you-want-to-continue'))), /*#__PURE__*/_react.default.createElement(_modal.default.Footer, {
          last: /*#__PURE__*/_react.default.createElement(_button.default.Group, {
            spaced: true
          }, /*#__PURE__*/_react.default.createElement(_button.default, {
            displayType: "secondary",
            onClick: onClose
          }, Liferay.Language.get('cancel')), /*#__PURE__*/_react.default.createElement(_button.default, {
            displayType: "warning",
            onClick: function handleSubmit() {
              var _objectToFormData;

              (0, _frontendJsWeb.fetch)(propagateContributedFragmentEntriesChangesURL, {
                body: (0, _frontendJsWeb.objectToFormData)((_objectToFormData = {}, _defineProperty(_objectToFormData, "".concat(namespace, "propagateChanges"), propagateChangesChecked), _defineProperty(_objectToFormData, "".concat(namespace, "propagateContributedFragmentChanges"), propagateContributedFragmentChangesChecked), _objectToFormData)),
                method: 'POST'
              }).then(function (response) {
                return response.json();
              }).then(function (_ref2) {
                var success = _ref2.success;

                if (success) {
                  (0, _frontendJsWeb.openToast)({
                    message: Liferay.Language.get('the-changes-in-the-contributed-fragments-have-been-propagated-successfully'),
                    title: Liferay.Language.get('success'),
                    type: 'success'
                  });
                  setDisablePropagateChangesButton(true);
                  setFeedbackMessage(FEEDBACK_MESSAGES.success);
                } else {
                  (0, _frontendJsWeb.openToast)({
                    message: Liferay.Language.get('something-went-wrong-and-the-changes-in-the-contributed-fragments-could-not-be-propagated.-please-try-again-later'),
                    title: Liferay.Language.get('error'),
                    type: 'danger'
                  });
                  setFeedbackMessage(FEEDBACK_MESSAGES.error);
                }

                setWarningModalVisible(false);
              });
            }
          }, Liferay.Language.get('continue')))
        })))
      );
    }
    //# sourceMappingURL=FragmentServiceConfiguration.js.map
  }
});
//# sourceMappingURL=FragmentServiceConfiguration.js.map