Liferay.Loader.define("dynamic-data-mapping-form-renderer@5.0.45/js/components/Field/ReactFieldAdapter.es", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/icon', 'frontend-js-metal-web$metal-soy', 'frontend-js-react-web$react', '../../hooks/usePage.es', '../../hooks/useResource.es', '../../util/ReactComponentAdapter.es', './Field.es', './ReactFieldAdapter.soy'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.default = exports.ReactFieldAdapter = void 0;

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

    var _metalSoy = _interopRequireDefault(require("frontend-js-metal-web$metal-soy"));

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

    var _usePage = require("../../hooks/usePage.es");

    var _useResource = require("../../hooks/useResource.es");

    var _ReactComponentAdapter = require("../../util/ReactComponentAdapter.es");

    var _Field = require("./Field.es");

    var _ReactFieldAdapter = _interopRequireDefault(require("./ReactFieldAdapter.soy"));

    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 _objectWithoutProperties(source, excluded) {
      if (source == null) return {};var target = _objectWithoutPropertiesLoose(source, excluded);var key, i;if (Object.getOwnPropertySymbols) {
        var sourceSymbolKeys = Object.getOwnPropertySymbols(source);for (i = 0; i < sourceSymbolKeys.length; i++) {
          key = sourceSymbolKeys[i];if (excluded.indexOf(key) >= 0) continue;if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;target[key] = source[key];
        }
      }return target;
    }

    function _objectWithoutPropertiesLoose(source, excluded) {
      if (source == null) return {};var target = {};var sourceKeys = Object.keys(source);var key, i;for (i = 0; i < sourceKeys.length; i++) {
        key = sourceKeys[i];if (excluded.indexOf(key) >= 0) continue;target[key] = source[key];
      }return target;
    }

    /**
     * This creates a compatibility layer for the Field component on React, allowing
     * it to be called by Metal+Soy file.
     *
     * This component creates a mask for the Field component, some DDM fields access
     * the `usePage` and we need to bring the `usePage` here since this component
     * will not have a React context above it.
     */
    var ReactFieldAdapter = function ReactFieldAdapter(_ref) {
      var fieldType = _ref.fieldType,
          instance = _ref.instance,
          field = _objectWithoutProperties(_ref, ["fieldType", "instance"]);

      var _useFieldTypesResourc = (0, _useResource.useFieldTypesResource)(),
          fieldTypes = _useFieldTypesResourc.resource;

      if (!fieldType || fieldType === '') {
        return null;
      }

      var emit = function emit(name, event) {
        instance.emit(name, _objectSpread(_objectSpread({}, event), {}, {
          fieldInstance: _objectSpread(_objectSpread({}, event.fieldInstance), {}, {
            element: instance.element
          })
        }));
      };

      return (/*#__PURE__*/_react.default.createElement(_usePage.PageProvider, {
          value: _objectSpread(_objectSpread({}, field), {}, {
            fieldTypes: fieldTypes
          })
        }, /*#__PURE__*/_react.default.createElement(_icon.ClayIconSpriteContext.Provider, {
          value: field.spritemap
        }, /*#__PURE__*/_react.default.createElement(_Field.Field, {
          field: _objectSpread(_objectSpread({}, field), {}, {
            type: fieldType
          }),
          onBlur: function onBlur(event) {
            return emit('fieldBlurred', event);
          },
          onChange: function onChange(event) {
            return emit('fieldEdited', event);
          },
          onFocus: function onFocus(event) {
            return emit('fieldFocused', event);
          }
        })))
      );
    };

    exports.ReactFieldAdapter = ReactFieldAdapter;
    var ReactComponentAdapter = (0, _ReactComponentAdapter.getConnectedReactComponentAdapter)(ReactFieldAdapter);

    _metalSoy.default.register(ReactComponentAdapter, _ReactFieldAdapter.default);

    var _default = ReactComponentAdapter;
    exports.default = _default;
    //# sourceMappingURL=ReactFieldAdapter.es.js.map
  }
});
//# sourceMappingURL=ReactFieldAdapter.es.js.map