"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.ValueWrapper = exports.DynamicPropWrapper = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var React = _interopRequireWildcard(require("react"));
var _excluded = ["__designMode", "value", "defaultValue"],
  _excluded2 = ["__designMode"];
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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; }
var createElement = React.createElement;
var ValueWrapper = function ValueWrapper(NextFormComponent, displayName) {
  var WrappedComponent = function WrappedComponent(props) {
    var __designMode = props.__designMode,
      value = props.value,
      defaultValue = props.defaultValue,
      otherProps = (0, _objectWithoutPropertiesLoose2["default"])(props, _excluded);
    var finalValue = __designMode === 'design' ? defaultValue : value;
    if (typeof finalValue !== 'undefined') {
      otherProps.value = finalValue;
    }
    return createElement(NextFormComponent, (0, _extends2["default"])({}, otherProps));
  };
  WrappedComponent.displayName = displayName;
  return WrappedComponent;
};
exports.ValueWrapper = ValueWrapper;
var DynamicPropWrapper = function DynamicPropWrapper(prop, NextFormComponent, displayName) {
  var WrappedComponent = function WrappedComponent(props) {
    var dynamicProp = prop;
    var defaultDynamicProp = "default" + prop.slice(0, 1).toUpperCase() + prop.slice(1);
    var __designMode = props.__designMode,
      otherProps = (0, _objectWithoutPropertiesLoose2["default"])(props, _excluded2);
    var dynamicPropValueValue = props[dynamicProp];
    var defaultDynamicPropValue = props[defaultDynamicProp];
    var finalValue = __designMode === 'design' ? defaultDynamicPropValue : dynamicPropValueValue;
    if (typeof finalValue !== 'undefined') {
      otherProps[dynamicProp] = finalValue;
    }
    return createElement(NextFormComponent, (0, _extends2["default"])({}, otherProps));
  };
  WrappedComponent.displayName = displayName;
  return WrappedComponent;
};
exports.DynamicPropWrapper = DynamicPropWrapper;