Liferay.Loader.define("layout-seo-web@1.0.45/js/seo/display_page_templates/components/MappingInput", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/form', 'frontend-js-react-web$prop-types', 'frontend-js-react-web$react', './MappingPanel'], 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 _form = _interopRequireWildcard(require("@frontend-taglib-clay$clayui/form"));

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

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

    var _MappingPanel = _interopRequireDefault(require("./MappingPanel"));

    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 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 _toConsumableArray(arr) {
      return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
    }

    function _nonIterableSpread() {
      throw new TypeError("Invalid attempt to spread non-iterable instance");
    }

    function _iterableToArray(iter) {
      if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
    }

    function _arrayWithoutHoles(arr) {
      if (Array.isArray(arr)) {
        for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
          arr2[i] = arr[i];
        }return arr2;
      }
    }

    var UNMAPPED_OPTION = {
      key: 'unmapped',
      label: "-- ".concat(Liferay.Language.get('unmapped'), " --")
    };

    function MappingInput(_ref) {
      var fieldType = _ref.fieldType,
          helpMessage = _ref.helpMessage,
          initialFields = _ref.initialFields,
          label = _ref.label,
          name = _ref.name,
          selectedFieldKey = _ref.selectedFieldKey,
          selectedSource = _ref.selectedSource;
      var fields = [UNMAPPED_OPTION].concat(_toConsumableArray(initialFields.filter(function (_ref2) {
        var type = _ref2.type;
        return type === fieldType;
      })));

      var _useState = (0, _react.useState)(selectedSource),
          _useState2 = _slicedToArray(_useState, 2),
          source = _useState2[0],
          setSource = _useState2[1];

      var _useState3 = (0, _react.useState)(fields.find(function (_ref3) {
        var key = _ref3.key;
        return key === selectedFieldKey;
      }) || UNMAPPED_OPTION),
          _useState4 = _slicedToArray(_useState3, 2),
          field = _useState4[0],
          setField = _useState4[1];

      var isActive = !!field && field.key !== UNMAPPED_OPTION.key;
      var inititalSourceLabel = selectedSource ? selectedSource.classTypeLabel || selectedSource.classNameLabel : '';

      return (/*#__PURE__*/_react.default.createElement(_form.default.Group, null, /*#__PURE__*/_react.default.createElement("label", {
          className: "control-label",
          htmlFor: name
        }, label), /*#__PURE__*/_react.default.createElement(_form.ClayInput.Group, null, /*#__PURE__*/_react.default.createElement(_form.ClayInput.GroupItem, null, /*#__PURE__*/_react.default.createElement(_form.ClayInput, {
          className: "dpt-mapping-input",
          id: name,
          readOnly: true,
          type: "text",
          value: "".concat(isActive && inititalSourceLabel && "".concat(inititalSourceLabel, ": ") || '').concat(field.label)
        }), /*#__PURE__*/_react.default.createElement(_form.ClayInput, {
          name: name,
          type: "hidden",
          value: field.key
        })), /*#__PURE__*/_react.default.createElement(_form.ClayInput.GroupItem, {
          shrink: true
        }, /*#__PURE__*/_react.default.createElement(_MappingPanel.default, {
          field: field,
          fields: fields,
          isActive: isActive,
          name: name,
          onChange: function handleOnchange(_ref4) {
            var field = _ref4.field,
                source = _ref4.source;
            setSource(source);
            setField(field);
          },
          source: _objectSpread(_objectSpread({}, source), {}, {
            initialValue: inititalSourceLabel
          })
        }))), helpMessage && /*#__PURE__*/_react.default.createElement(_form.default.Text, null, helpMessage))
      );
    }

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