Liferay.Loader.define("dynamic-data-mapping-form-web@3.0.69/admin/js/components/ShareFormModal/ShareFormModal.es", ['module', 'exports', 'require', 'frontend-taglib-clay$clay-modal', 'dynamic-data-mapping-form-renderer/js/util/fetch.es', 'frontend-js-metal-web$metal-dom', 'frontend-js-metal-web$metal-events', 'frontend-js-metal-web$metal-jsx', './Email.es', './Link.es'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.default = void 0;

    var _clayModal = _interopRequireDefault(require("frontend-taglib-clay$clay-modal"));

    var _fetch = require("dynamic-data-mapping-form-renderer/js/util/fetch.es");

    var _metalDom = _interopRequireDefault(require("frontend-js-metal-web$metal-dom"));

    var _metalEvents = require("frontend-js-metal-web$metal-events");

    var _metalJsx = _interopRequireWildcard(require("frontend-js-metal-web$metal-jsx"));

    var _Email = _interopRequireDefault(require("./Email.es"));

    var _Link = _interopRequireDefault(require("./Link.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 _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);
    }

    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 _classCallCheck(instance, Constructor) {
      if (!(instance instanceof Constructor)) {
        throw new TypeError("Cannot call a class as a function");
      }
    }

    function _defineProperties(target, props) {
      for (var i = 0; i < props.length; i++) {
        var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);
      }
    }

    function _createClass(Constructor, protoProps, staticProps) {
      if (protoProps) _defineProperties(Constructor.prototype, protoProps);if (staticProps) _defineProperties(Constructor, staticProps);return Constructor;
    }

    function _possibleConstructorReturn(self, call) {
      if (call && (_typeof(call) === "object" || typeof call === "function")) {
        return call;
      }return _assertThisInitialized(self);
    }

    function _assertThisInitialized(self) {
      if (self === void 0) {
        throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
      }return self;
    }

    function _get(target, property, receiver) {
      if (typeof Reflect !== "undefined" && Reflect.get) {
        _get = Reflect.get;
      } else {
        _get = function _get(target, property, receiver) {
          var base = _superPropBase(target, property);if (!base) return;var desc = Object.getOwnPropertyDescriptor(base, property);if (desc.get) {
            return desc.get.call(receiver);
          }return desc.value;
        };
      }return _get(target, property, receiver || target);
    }

    function _superPropBase(object, property) {
      while (!Object.prototype.hasOwnProperty.call(object, property)) {
        object = _getPrototypeOf(object);if (object === null) break;
      }return object;
    }

    function _getPrototypeOf(o) {
      _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
        return o.__proto__ || Object.getPrototypeOf(o);
      };return _getPrototypeOf(o);
    }

    function _inherits(subClass, superClass) {
      if (typeof superClass !== "function" && superClass !== null) {
        throw new TypeError("Super expression must either be null or a function");
      }subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } });if (superClass) _setPrototypeOf(subClass, superClass);
    }

    function _setPrototypeOf(o, p) {
      _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
        o.__proto__ = p;return o;
      };return _setPrototypeOf(o, p);
    }

    var ShareFormModal = /*#__PURE__*/function (_Component) {
      _inherits(ShareFormModal, _Component);

      function ShareFormModal() {
        _classCallCheck(this, ShareFormModal);

        return _possibleConstructorReturn(this, _getPrototypeOf(ShareFormModal).apply(this, arguments));
      }

      _createClass(ShareFormModal, [{
        key: "attached",
        value: function attached() {
          this._eventHandler.add(_metalDom.default.on('.nav-item > .lfr-ddm-share-url-button', 'click', this._handleShareButtonClicked.bind(this)));
        }
      }, {
        key: "close",
        value: function close() {
          this.refs.shareFormModalRef.emit('hide');
        }
      }, {
        key: "created",
        value: function created() {
          this._eventHandler = new _metalEvents.EventHandler();
        }
      }, {
        key: "disposeInternal",
        value: function disposeInternal() {
          var modalBackdrop = document.querySelector('.modal-backdrop');

          _metalDom.default.exitDocument(modalBackdrop);

          _get(_getPrototypeOf(ShareFormModal.prototype), "disposeInternal", this).call(this);

          this._eventHandler.removeAllListeners();
        }
      }, {
        key: "open",
        value: function open() {
          this.refs.shareFormModalRef.refs.emailRef.init();
          this.refs.shareFormModalRef.refs.linkRef.init();
          this.refs.shareFormModalRef.visible = true;
        }
      }, {
        key: "render",
        value: function render() {
          var _this$props = this.props,
              autocompleteUserURL = _this$props.autocompleteUserURL,
              spritemap = _this$props.spritemap,
              url = _this$props.url;
          IncrementalDOM.elementOpen("div", null, null, "class", "share-form-modal");
          IncrementalDOM.elementVoid(_clayModal.default, null, null, "body", iDOMHelpers.jsxWrapper(function (_Liferay$Language$get, _spritemap, _url, _Liferay$Language$get2, _autocompleteUserURL, _this$props$localized, _spritemap2, _url2) {
            IncrementalDOM.elementOpen("div", null, null, "class", "share-form-modal-items");
            IncrementalDOM.elementOpen("div", null, null, "class", "share-form-modal-item");
            IncrementalDOM.elementOpen("div", null, null, "class", "popover-header");
            iDOMHelpers.renderArbitrary(_Liferay$Language$get);
            IncrementalDOM.elementClose("div");
            IncrementalDOM.elementOpen("div", null, null, "class", "popover-body");
            IncrementalDOM.elementVoid(_Link.default, null, null, "spritemap", _spritemap, "url", _url, "ref", "linkRef");
            IncrementalDOM.elementClose("div");
            IncrementalDOM.elementClose("div");
            IncrementalDOM.elementOpen("div", null, null, "class", "share-form-modal-item");
            IncrementalDOM.elementOpen("div", null, null, "class", "popover-header");
            iDOMHelpers.renderArbitrary(_Liferay$Language$get2);
            IncrementalDOM.elementClose("div");
            IncrementalDOM.elementOpen("div", null, null, "class", "popover-body");
            IncrementalDOM.elementVoid(_Email.default, null, null, "autocompleteUserURL", _autocompleteUserURL, "localizedName", _this$props$localized, "spritemap", _spritemap2, "url", _url2, "ref", "emailRef");
            IncrementalDOM.elementClose("div");
            IncrementalDOM.elementClose("div");
            return IncrementalDOM.elementClose("div");
          }, [Liferay.Language.get('link'), spritemap, url, Liferay.Language.get('email'), autocompleteUserURL, this.props.localizedName, spritemap, url]), "events", {
            clickButton: this._handleClickFooterButton.bind(this),
            hide: this._handleShareFormModalClosed.bind(this)
          }, "footerButtons", [{
            alignment: 'right',
            label: Liferay.Language.get('cancel'),
            style: 'secondary',
            type: 'close'
          }, {
            alignment: 'right',
            label: Liferay.Language.get('done'),
            style: 'primary',
            type: 'button'
          }], "spritemap", spritemap, "title", Liferay.Language.get('share'), "ref", 'shareFormModalRef', "size", 'lg');
          return IncrementalDOM.elementClose("div");
        }
      }, {
        key: "showNotification",
        value: function showNotification(message, error) {
          var parentOpenToast = Liferay.Util.getOpener().Liferay.Util.openToast;
          var openToastParams = {
            message: message
          };

          if (error) {
            openToastParams.title = Liferay.Language.get('error');
            openToastParams.type = 'danger';
          } else {
            openToastParams.title = Liferay.Language.get('success');
          }

          parentOpenToast(openToastParams);
        }
      }, {
        key: "submitEmailContent",
        value: function submitEmailContent() {
          var _data,
              _this = this;

          var _this$props2 = this.props,
              portletNamespace = _this$props2.portletNamespace,
              shareFormInstanceURL = _this$props2.shareFormInstanceURL;
          var emailContent = this.refs.shareFormModalRef.refs.emailRef.state.emailContent;
          var addresses = emailContent.addresses;

          if (!addresses || !addresses.length) {
            return;
          }

          var data = (_data = {}, _defineProperty(_data, "".concat(portletNamespace, "addresses"), addresses.map(function (_ref) {
            var label = _ref.label;
            return label;
          }).join(',')), _defineProperty(_data, "".concat(portletNamespace, "message"), emailContent.message), _defineProperty(_data, "".concat(portletNamespace, "subject"), emailContent.subject), _data);
          (0, _fetch.makeFetch)({
            body: (0, _fetch.convertToFormData)(data),
            method: 'POST',
            url: shareFormInstanceURL
          }).then(function (response) {
            return response.successMessage ? _this.showNotification(response.successMessage) : _this.showNotification(response.errorMessage, true);
          }).catch(function (error) {
            throw new Error(error);
          });
        }
      }, {
        key: "_handleClickFooterButton",
        value: function _handleClickFooterButton(event) {
          if (event.target.classList.contains('btn-primary')) {
            this.submitEmailContent();
            this.close();
          }
        }
      }, {
        key: "_handleShareButtonClicked",
        value: function _handleShareButtonClicked() {
          this.open();
        }
      }, {
        key: "_handleShareFormModalClosed",
        value: function _handleShareFormModalClosed(event) {
          this.emit('shareFormModalClosed', event);
        }
      }]);

      return ShareFormModal;
    }(_metalJsx.default);

    ShareFormModal.PROPS = {
      /**
       * @default undefined
       * @instance
       * @memberof ShareFormModal
       * @type {!string}
       */
      autocompleteUserURL: _metalJsx.Config.string(),

      /**
       * @default undefined
       * @instance
       * @memberof ShareFormModal
       * @type {!object}
       */
      localizedName: _metalJsx.Config.object(),

      /**
       * @default undefined
       * @instance
       * @memberof ShareFormModal
       * @type {!string}
       */
      portletNamespace: _metalJsx.Config.string(),

      /**
       * @default undefined
       * @instance
       * @memberof ShareFormModal
       * @type {!string}
       */
      shareFormInstanceURL: _metalJsx.Config.string(),

      /**
       * @default undefined
       * @instance
       * @memberof ShareFormModal
       * @type {!string}
       */
      spritemap: _metalJsx.Config.string(),

      /**
       * @default undefined
       * @instance
       * @memberof ShareFormModal
       * @type {!string}
       */
      url: _metalJsx.Config.string()
    };
    var _default = ShareFormModal;
    exports.default = _default;
    //# sourceMappingURL=ShareFormModal.es.js.map
  }
});
//# sourceMappingURL=ShareFormModal.es.js.map