Liferay.Loader.define("redirect-web@1.0.43/js/DestinationUrlInput", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/button', '@frontend-taglib-clay$clayui/form', '@frontend-taglib-clay$clayui/icon', 'frontend-js-react-web$prop-types', '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 = void 0;

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

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

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

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

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

    function _interopRequireDefault(obj) {
      return obj && obj.__esModule ? obj : { default: obj };
    }

    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 _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 REGEX_URL = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+|(https?:\/\/|www.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%/.\w-_]*)?\??(?:[-+=&;%@.\w_]*)#?(?:[\w]*))((.*):(\d*)\/?(.*))?)/;
    var STR_BLANK = '';

    var DestinationUrlInput = function DestinationUrlInput(_ref) {
      var _ref$autofocus = _ref.autofocus,
          autofocus = _ref$autofocus === void 0 ? false : _ref$autofocus,
          _ref$initialDestinati = _ref.initialDestinationUrl,
          initialDestinationUrl = _ref$initialDestinati === void 0 ? STR_BLANK : _ref$initialDestinati,
          namespace = _ref.namespace;

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

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

      var _useState5 = (0, _react.useState)(initialDestinationUrl),
          _useState6 = _slicedToArray(_useState5, 2),
          destinationUrl = _useState6[0],
          setDestinationUrl = _useState6[1];

      var isAbsoluteUrl = function isAbsoluteUrl(url) {
        return REGEX_URL && REGEX_URL.test(url);
      };

      return (/*#__PURE__*/_react.default.createElement(_form.default.Group, {
          className: requiredError || urlError ? 'has-error' : STR_BLANK
        }, /*#__PURE__*/_react.default.createElement("label", {
          htmlFor: "".concat(namespace, "destinationURL")
        }, Liferay.Language.get('destination-url'), /*#__PURE__*/_react.default.createElement("span", {
          className: "inline-item-after reference-mark"
        }, /*#__PURE__*/_react.default.createElement(_icon.default, {
          symbol: 'asterisk'
        }), /*#__PURE__*/_react.default.createElement("span", {
          className: "hide-accessible"
        }, Liferay.Language.get('required')))), /*#__PURE__*/_react.default.createElement(_form.ClayInput.Group, null, /*#__PURE__*/_react.default.createElement(_form.ClayInput.GroupItem, {
          prepend: true
        }, /*#__PURE__*/_react.default.createElement(_form.ClayInput, {
          "aria-label": Liferay.Language.get('destination-url'),
          autoFocus: autofocus,
          id: "".concat(namespace, "destinationURL"),
          name: "".concat(namespace, "destinationURL"),
          onBlur: function onBlur(_ref2) {
            var currentTarget = _ref2.currentTarget;
            setRequiredError(!currentTarget.value);
            setUrlError(!isAbsoluteUrl(currentTarget.value));
          },
          onChange: function onChange(_ref3) {
            var currentTarget = _ref3.currentTarget;
            return setDestinationUrl(currentTarget.value);
          },
          type: "text",
          value: destinationUrl
        })), /*#__PURE__*/_react.default.createElement(_form.ClayInput.GroupItem, {
          append: true,
          shrink: true
        }, /*#__PURE__*/_react.default.createElement(_button.ClayButtonWithIcon, {
          disabled: destinationUrl === STR_BLANK || !isAbsoluteUrl(destinationUrl),
          displayType: "secondary",
          onClick: function handleTryRedirection() {
            var testUrl = destinationUrl;
            var protocol = 'http';

            if (!testUrl.startsWith(protocol)) {
              testUrl = protocol + '://' + testUrl;
            }

            window.open(testUrl, '_blank');
          },
          symbol: "shortcut",
          title: Liferay.Language.get('check-url')
        }))), requiredError && /*#__PURE__*/_react.default.createElement(_form.default.FeedbackGroup, null, /*#__PURE__*/_react.default.createElement(_form.default.FeedbackItem, null, Liferay.Language.get('this-field-is-required'))), !requiredError && urlError && /*#__PURE__*/_react.default.createElement(_form.default.FeedbackGroup, null, /*#__PURE__*/_react.default.createElement(_form.default.FeedbackItem, null, /*#__PURE__*/_react.default.createElement(_form.default.FeedbackIndicator, {
          symbol: "exclamation-full"
        }), Liferay.Language.get('this-url-is-not-supported')), /*#__PURE__*/_react.default.createElement("div", {
          className: "small",
          dangerouslySetInnerHTML: {
            __html: Liferay.Util.sub(Liferay.Language.get('enter-an-absolute-url'), '<em>', '</em>')
          }
        })))
      );
    };

    var _default = DestinationUrlInput;
    exports.default = _default;
    //# sourceMappingURL=DestinationUrlInput.js.map
  }
});
//# sourceMappingURL=DestinationUrlInput.js.map