Liferay.Loader.define("layout-content-page-editor-web@2.0.110/page_editor/plugins/page-structure/components/item-configuration-panels/MappingPanel", ['module', 'exports', 'require', 'frontend-js-react-web$react', '../../../../app/components/CollectionItemContext', '../../../../app/config/constants/backgroundImageFragmentEntryProcessor', '../../../../app/config/constants/editableFragmentEntryProcessor', '../../../../app/config/constants/editableTypes', '../../../../app/selectors/selectEditableValue', '../../../../app/store/index', '../../../../app/thunks/updateEditableValues', '../../../../app/utils/isMapped', '../../../../common/components/MappingSelector', '../../../../prop-types/index'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.MappingPanel = MappingPanel;

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

    var _CollectionItemContext = require("../../../../app/components/CollectionItemContext");

    var _backgroundImageFragmentEntryProcessor = require("../../../../app/config/constants/backgroundImageFragmentEntryProcessor");

    var _editableFragmentEntryProcessor = require("../../../../app/config/constants/editableFragmentEntryProcessor");

    var _editableTypes = require("../../../../app/config/constants/editableTypes");

    var _selectEditableValue = _interopRequireDefault(require("../../../../app/selectors/selectEditableValue"));

    var _index = require("../../../../app/store/index");

    var _updateEditableValues = _interopRequireDefault(require("../../../../app/thunks/updateEditableValues"));

    var _isMapped = _interopRequireDefault(require("../../../../app/utils/isMapped"));

    var _MappingSelector = _interopRequireDefault(require("../../../../common/components/MappingSelector"));

    var _index2 = require("../../../../prop-types/index");

    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 MappingPanel(_ref) {
      var item = _ref.item;
      var collectionConfig = (0, _CollectionItemContext.useCollectionConfig)();
      var editableId = item.editableId,
          fragmentEntryLinkId = item.fragmentEntryLinkId,
          type = item.type;
      var dispatch = (0, _index.useDispatch)();
      var state = (0, _index.useSelector)(function (state) {
        return state;
      });
      var fragmentEntryLink = state.fragmentEntryLinks[fragmentEntryLinkId];
      var processoryKey = type === _editableTypes.EDITABLE_TYPES.backgroundImage ? _backgroundImageFragmentEntryProcessor.BACKGROUND_IMAGE_FRAGMENT_ENTRY_PROCESSOR : _editableFragmentEntryProcessor.EDITABLE_FRAGMENT_ENTRY_PROCESSOR;
      var editableValue = (0, _selectEditableValue.default)(state, fragmentEntryLinkId, editableId, processoryKey);

      return (/*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, collectionConfig && /*#__PURE__*/_react.default.createElement("p", {
          className: "page-editor__mapping-panel__helper text-secondary"
        }, Liferay.Language.get('collection-mapping-help')), /*#__PURE__*/_react.default.createElement(_MappingSelector.default, {
          fieldType: type,
          mappedItem: editableValue,
          onMappingSelect: function updateEditableValue(newEditableValue) {
            var nextEditableValues = _objectSpread(_objectSpread({}, fragmentEntryLink.editableValues), {}, _defineProperty({}, processoryKey, _objectSpread(_objectSpread({}, fragmentEntryLink.editableValues[processoryKey]), {}, _defineProperty({}, editableId, _objectSpread({
              config: (0, _isMapped.default)(newEditableValue) ? _objectSpread(_objectSpread({}, editableValue.config), {}, {
                alt: '',
                imageTitle: ''
              }) : editableValue.config,
              defaultValue: editableValue.defaultValue
            }, newEditableValue)))));

            dispatch((0, _updateEditableValues.default)({
              editableValues: nextEditableValues,
              fragmentEntryLinkId: fragmentEntryLinkId,
              segmentsExperienceId: state.segmentsExperienceId
            }));
          }
        }))
      );
    }
    //# sourceMappingURL=MappingPanel.js.map
  }
});
//# sourceMappingURL=MappingPanel.js.map