Liferay.Loader.define("flags-taglib@5.0.21/flags/js/components/Flags.es", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/button', '@frontend-taglib-clay$clayui/icon', '@frontend-taglib-clay$clayui/modal', 'frontend-js-react-web', 'frontend-js-web', 'frontend-js-react-web$prop-types', 'frontend-js-react-web$react', '../ThemeContext.es', '../constants.es', './FlagsModal.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 _button = _interopRequireDefault(require("@frontend-taglib-clay$clayui/button"));

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

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

    var _frontendJsReactWeb = require("frontend-js-react-web");

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

    var _propTypes = _interopRequireDefault(require("frontend-js-react-web$prop-types"));

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

    var _ThemeContext = _interopRequireDefault(require("../ThemeContext.es"));

    var _constants = require("../constants.es");

    var _FlagsModal = _interopRequireDefault(require("./FlagsModal.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;
    }

    var Flags = function Flags(_ref) {
      var baseData = _ref.baseData,
          captchaURI = _ref.captchaURI,
          companyName = _ref.companyName,
          _ref$disabled = _ref.disabled,
          disabled = _ref$disabled === void 0 ? false : _ref$disabled,
          _ref$forceLogin = _ref.forceLogin,
          forceLogin = _ref$forceLogin === void 0 ? false : _ref$forceLogin,
          _ref$message = _ref.message,
          message = _ref$message === void 0 ? Liferay.Language.get('report') : _ref$message,
          _ref$onlyIcon = _ref.onlyIcon,
          onlyIcon = _ref$onlyIcon === void 0 ? false : _ref$onlyIcon,
          pathTermsOfUse = _ref.pathTermsOfUse,
          reasons = _ref.reasons,
          _ref$signedIn = _ref.signedIn,
          signedIn = _ref$signedIn === void 0 ? false : _ref$signedIn,
          uri = _ref.uri;

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

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

      var _useState5 = (0, _react.useState)(forceLogin ? _constants.STATUS_LOGIN : _constants.STATUS_REPORT),
          _useState6 = _slicedToArray(_useState5, 2),
          status = _useState6[0],
          setStatus = _useState6[1];

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

      var _useState9 = (0, _react.useState)(''),
          _useState10 = _slicedToArray(_useState9, 2),
          otherReason = _useState10[0],
          setOtherReason = _useState10[1];

      var _useState11 = (0, _react.useState)(''),
          _useState12 = _slicedToArray(_useState11, 2),
          reporterEmailAddress = _useState12[0],
          setReporterEmailAddress = _useState12[1];

      var _useState13 = (0, _react.useState)(Object.keys(reasons)[0]),
          _useState14 = _slicedToArray(_useState13, 2),
          selectedReason = _useState14[0],
          setSelectedReason = _useState14[1];

      var _useContext = (0, _react.useContext)(_ThemeContext["default"]),
          namespace = _useContext.namespace;

      var getReason = function getReason() {
        if (selectedReason === _constants.OTHER_REASON_VALUE) {
          return otherReason || Liferay.Language.get('no-reason-specified');
        }

        return selectedReason;
      };

      var isMounted = (0, _frontendJsReactWeb.useIsMounted)();

      var _useModal = (0, _modal.useModal)({
        onClose: function handleClickClose() {
          setError(false);
          setReportDialogOpen(false);
        }
      }),
          observer = _useModal.observer,
          onClose = _useModal.onClose;

      return _react["default"].createElement(_react["default"].Fragment, null, _react["default"].createElement(_button["default"], {
        className: "btn-outline-borderless btn-outline-secondary ".concat(onlyIcon ? 'lfr-portal-tooltip' : ''),
        "data-title": onlyIcon ? message : undefined,
        disabled: disabled,
        displayType: "secondary",
        monospaced: onlyIcon,
        onClick: function handleClickShow() {
          setReportDialogOpen(true);
        },
        small: true
      }, _react["default"].createElement("span", {
        className: !onlyIcon ? 'inline-item inline-item-before' : undefined
      }, _react["default"].createElement(_icon["default"], {
        symbol: "flag-empty"
      })), _react["default"].createElement("span", {
        className: onlyIcon ? 'sr-only' : undefined
      }, message)), reportDialogOpen && _react["default"].createElement(_FlagsModal["default"], {
        captchaURI: captchaURI,
        companyName: companyName,
        error: error,
        handleClose: onClose,
        handleInputChange: function handleInputChange(event) {
          var target = event.target;
          var value = target.type === 'checkbox' ? target.checked : target.value.trim();
          var name = target.name;

          if (name === 'otherReason') {
            setOtherReason(value);
          } else if (name === 'reporterEmailAddress') {
            setReporterEmailAddress(value);
          } else if (name === 'selectedReason') {
            setSelectedReason(value);
          }
        },
        handleSubmit: function handleSubmitReport(event) {
          event.preventDefault();
          setIsSending(true);

          var formDataObj = _objectSpread({}, baseData, _defineProperty({}, "".concat(namespace, "reason"), getReason()));

          if (!signedIn) {
            formDataObj["".concat(namespace, "reporterEmailAddress")] = reporterEmailAddress;
          }

          (0, _frontendJsWeb.fetch)(uri, {
            body: (0, _frontendJsWeb.objectToFormData)(formDataObj, new FormData(event.target)),
            method: 'post'
          }).then(function (res) {
            return res.json();
          }).then(function (_ref2) {
            var error = _ref2.error;

            if (isMounted()) {
              setError(error);
              setIsSending(false);

              if (!error) {
                setStatus(_constants.STATUS_SUCCESS);
              }
            }
          })["catch"](function () {
            if (isMounted()) {
              setStatus(_constants.STATUS_ERROR);
            }
          });
        },
        isSending: isSending,
        observer: observer,
        pathTermsOfUse: pathTermsOfUse,
        reasons: reasons,
        selectedReason: selectedReason,
        signedIn: signedIn,
        status: status
      }));
    };

    var _default = Flags;
    exports["default"] = _default;
    //# sourceMappingURL=Flags.es.js.map
  }
});
//# sourceMappingURL=Flags.es.js.map